
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>凝练才是美--抽象类 接口 内部类 · Java笔记Blog</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="snowdreams1006">
        
        
    
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-timeline/timeline.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="java13.html" />
    
    
    <link rel="prev" href="java12.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://blog.lichongbing.com/" target="_blank" class="custom-link">blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="java5.html">
            
                <a href="java5.html">
            
                    
                    Java基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="java.html">
            
                <a href="java.html">
            
                    
                    Java知识思维导图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="java5.html">
            
                <a href="java5.html#2">
            
                    
                    Java开发环境搭建
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="java5.html">
            
                <a href="java5.html#21">
            
                    
                    1.1 Java开发环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="java5.html">
            
                <a href="java5.html#22">
            
                    
                    1.2 安装Java开发工具箱
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="java6.html">
            
                <a href="java6.html#3">
            
                    
                    Java程序要素概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="java7.html">
            
                <a href="java7.html">
            
                    
                    Java编程基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="java8.html">
            
                <a href="java8.html">
            
                    
                    基础编程元素--运算符 表达式 语句与流程控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="java9.html">
            
                <a href="java9.html">
            
                    
                    常用的数据结构--数组与枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="java10.html">
            
                <a href="java10.html">
            
                    
                    面向对象设计的核心--类与对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="java11.html">
            
                <a href="java11.html">
            
                    
                    重复调用的代码块--方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="java12.html">
            
                <a href="java12.html">
            
                    
                    面向对象设计的精华--类的封装 继承 多态
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.9.1" data-path="java12.html">
            
                <a href="java12.html#1">
            
                    
                    8.1 面向对象的三大特点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.2" data-path="java12.html">
            
                <a href="java12.html#4">
            
                    
                    8.2 封装的实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.3" data-path="java12.html">
            
                <a href="java12.html#7">
            
                    
                    8.3 继承的实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.4" data-path="java12.html">
            
                <a href="java12.html#8">
            
                    
                    8.4 深度认识类的继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.5" data-path="java12.html">
            
                <a href="java12.html#9">
            
                    
                    8.5 覆写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.6" data-path="java12.html">
            
                <a href="java12.html#12">
            
                    
                    8.6 多态的实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.7" data-path="java12.html">
            
                <a href="java12.html#10">
            
                    
                    8.7 高手点拨
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.8" data-path="java12.html">
            
                <a href="java12.html#11">
            
                    
                    8.8 实战练习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.2.10" data-path="java13.html">
            
                <a href="java13.html">
            
                    
                    凝练才是美--抽象类 接口 内部类
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.10.1" data-path="java13.html">
            
                <a href="java13.html#1">
            
                    
                    9.1 抽象类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.2" data-path="java13.html">
            
                <a href="java13.html#2">
            
                    
                    9.2 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.3" data-path="java13.html">
            
                <a href="java13.html#3">
            
                    
                    9.3 内部类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.4" data-path="java13.html">
            
                <a href="java13.html#4">
            
                    
                    9.4 匿名内部类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.5" data-path="java13.html">
            
                <a href="java13.html#5">
            
                    
                    9.5 匿名对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.6" data-path="java13.html">
            
                <a href="java13.html#6">
            
                    
                    9.6 高手点拨
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.7" data-path="java13.html">
            
                <a href="java13.html#7">
            
                    
                    9.7 实战练习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="java14.html">
            
                <a href="java14.html">
            
                    
                    更灵活的设计--泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="java15.html">
            
                <a href="java15.html">
            
                    
                    更强大和方便的功能--注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" >
            
                <span>
            
                    
                    设计实践--常用的设计模式
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" >
            
                <span>
            
                    
                    存储类的仓库--Java常用类库
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" >
            
                <span>
            
                    
                    防患未然--异常的捕获与处理
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" >
            
                <span>
            
                    
                    齐头并进，并发任务的处理--多线程
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.17" >
            
                <span>
            
                    
                    文件I/O操作
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.18" >
            
                <span>
            
                    
                    Java反射
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.19" >
            
                <span>
            
                    
                    数据持久化方法--对象序列化
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.20" >
            
                <span>
            
                    
                    Maven Git Linux的基础使用
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="java6.html">
            
                <a href="java6.html">
            
                    
                    JavaWeb基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" >
            
                <span>
            
                    
                    JavaWeb的服务器与ide工具
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" >
            
                <span>
            
                    
                    JSP基本语法
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" >
            
                <span>
            
                    
                    JSP内置对象
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" >
            
                <span>
            
                    
                    JavaBean技术
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" >
            
                <span>
            
                    
                    Servlet技术
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" >
            
                <span>
            
                    
                    文件的上传与下载
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" >
            
                <span>
            
                    
                    过滤器和监听器
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" >
            
                <span>
            
                    
                    JavaWeb的数据库操作
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" >
            
                <span>
            
                    
                    EL表达式语言
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" >
            
                <span>
            
                    
                    JSTL标签
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    JavaWeb前端
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" >
            
                <span>
            
                    
                    HTML与CSS网页开发基础
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" >
            
                <span>
            
                    
                    JavaScript脚本语言
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" >
            
                <span>
            
                    
                    Ajax技术
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" >
            
                <span>
            
                    
                    JQuery技术
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" >
            
                <span>
            
                    
                    JSON技术
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" >
            
                <span>
            
                    
                    Java正则表达式
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" >
            
                <span>
            
                    
                    Vue.js
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" >
            
                <span>
            
                    
                    BootStap框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" >
            
                <span>
            
                    
                    Flutter框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" >
            
                <span>
            
                    
                    Angular框架 
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" >
            
                <span>
            
                    
                    webpack
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" >
            
                <span>
            
                    
                    微信小程序
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    JavaWeb数据库
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" >
            
                <span>
            
                    
                    MySQL
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" >
            
                <span>
            
                    
                    JDBC
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" >
            
                <span>
            
                    
                    C3P0
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" >
            
                <span>
            
                    
                    Druid
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    JavaWeb强化
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" >
            
                <span>
            
                    
                    设计模式
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" >
            
                <span>
            
                    
                    JVM优化
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" >
            
                <span>
            
                    
                    数据结构算法
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" >
            
                <span>
            
                    
                    多线程高级
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" >
            
                <span>
            
                    
                    MINA
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" >
            
                <span>
            
                    
                    Netty
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" >
            
                <span>
            
                    
                    NIO
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    JavaWeb框架
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" >
            
                <span>
            
                    
                    Struct2框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" >
            
                <span>
            
                    
                    JPA
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" >
            
                <span>
            
                    
                    Spring Data
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" >
            
                <span>
            
                    
                    Hibemate技术
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" >
            
                <span>
            
                    
                    Spring核心之IoC
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" >
            
                <span>
            
                    
                    Spring核心之AOP
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" >
            
                <span>
            
                    
                    Spring MVC框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" >
            
                <span>
            
                    
                    Mybatis框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" >
            
                <span>
            
                    
                    Mybatis Plus
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                    JavaWeb业务解决方案
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" >
            
                <span>
            
                    
                    ElasticSearch
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" >
            
                <span>
            
                    
                    Kibana
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" >
            
                <span>
            
                    
                    Logstash
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" >
            
                <span>
            
                    
                    LOG4J
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" >
            
                <span>
            
                    
                    Logback
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" >
            
                <span>
            
                    
                    SLF4J
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" >
            
                <span>
            
                    
                    Solr
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" >
            
                <span>
            
                    
                    D3
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" >
            
                <span>
            
                    
                    JCL
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" >
            
                <span>
            
                    
                    AntV
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.11" >
            
                <span>
            
                    
                    Beats
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.12" >
            
                <span>
            
                    
                    Lucene
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.13" >
            
                <span>
            
                    
                    POI
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.14" >
            
                <span>
            
                    
                    FreeMaker
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.15" >
            
                <span>
            
                    
                    Thymeleaf
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.16" >
            
                <span>
            
                    
                    Shiro
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.17" >
            
                <span>
            
                    
                    Spring Security
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.18" >
            
                <span>
            
                    
                    JasperReport
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.19" >
            
                <span>
            
                    
                    Quartz
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.20" >
            
                <span>
            
                    
                    Elastic-Job
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.21" >
            
                <span>
            
                    
                    Activiti
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.22" >
            
                <span>
            
                    
                    微信支付
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.23" >
            
                <span>
            
                    
                    支付宝支付
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.24" >
            
                <span>
            
                    
                    百度地图
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.25" >
            
                <span>
            
                    
                    高德地图
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" >
            
                <span>
            
                    
                    JavaWeb中介组件
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" >
            
                <span>
            
                    
                    Redis框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" >
            
                <span>
            
                    
                    FastDFS
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" >
            
                <span>
            
                    
                    定时任务
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" >
            
                <span>
            
                    
                    RabbitMQ
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" >
            
                <span>
            
                    
                    RocketMQ
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" >
            
                <span>
            
                    
                    JMS
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" >
            
                <span>
            
                    
                    MyCat
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" >
            
                <span>
            
                    
                    RabbitMQ
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.9" >
            
                <span>
            
                    
                    Kafka
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.10" >
            
                <span>
            
                    
                    Sharding-JDBC
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.11" >
            
                <span>
            
                    
                    Neo4j
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.12" >
            
                <span>
            
                    
                    MongoDB
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.13" >
            
                <span>
            
                    
                    ELK
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.14" >
            
                <span>
            
                    
                    Restful风格编程
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.15" >
            
                <span>
            
                    
                    Swagger文档
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.16" >
            
                <span>
            
                    
                    JMeter
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" >
            
                <span>
            
                    
                    JavaWeb微服务分布框架
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" >
            
                <span>
            
                    
                    Spring Boot框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" >
            
                <span>
            
                    
                    Spring Cloud框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" >
            
                <span>
            
                    
                    Zookeeper
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" >
            
                <span>
            
                    
                    Dubbo框架
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" >
            
                <span>
            
                    
                    Eureka
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" >
            
                <span>
            
                    
                    Consul
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" >
            
                <span>
            
                    
                    Hystrix
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" >
            
                <span>
            
                    
                    Zuul
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" >
            
                <span>
            
                    
                    Gateway
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.10" >
            
                <span>
            
                    
                    Skywalking
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.11" >
            
                <span>
            
                    
                    Pinpoint
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" >
            
                <span>
            
                    
                    JavaWeb部署
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" >
            
                <span>
            
                    
                    Docker
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" >
            
                <span>
            
                    
                    项目构建
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="java4.html">
            
                <a href="java4.html#1">
            
                    
                    JavaWeb实战项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="java4.html">
            
                <a href="java4.html#2">
            
                    
                    微人事项目实战
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="java16.html">
            
                <a href="java16.html">
            
                    
                    新蜂商城
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="moutn10.html">
            
                <a href="moutn10.html">
            
                    
                    2020年10月账本
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="day23.html">
            
                <a href="day23.html">
            
                    
                    10月23日
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="day29.html">
            
                <a href="day29.html">
            
                    
                    10月29日
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="moutn11.md">
            
                <span>
            
                    
                    2020年11月账本
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >凝练才是美--抽象类 接口 内部类</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
<div id="vip-container">
    <h1 id="&#x51DD;&#x7EC3;&#x624D;&#x662F;&#x7F8E;&#x2014;&#x2014;&#x62BD;&#x8C61;&#x7C7B;&#x3001;&#x63A5;&#x53E3;&#x4E0E;&#x5185;&#x90E8;&#x7C7B;">&#x51DD;&#x7EC3;&#x624D;&#x662F;&#x7F8E;&#x2014;&#x2014;&#x62BD;&#x8C61;&#x7C7B;&#x3001;&#x63A5;&#x53E3;&#x4E0E;&#x5185;&#x90E8;&#x7C7B;</h1>
<blockquote>
<p>&#x62BD;&#x8C61;&#x7C7B;&#x3001;&#x63A5;&#x53E3;&#x548C;&#x5185;&#x90E8;&#x7C7B;&#x4E3A;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x5C06;&#x63A5;&#x53E3;&#x4E0E;&#x5B9E;&#x73B0;&#x5206;&#x79BB;&#x7684;&#x66F4;&#x52A0;&#x7ED3;&#x6784;&#x5316;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x6B63;&#x662F;&#x7531;&#x4E8E;&#x8FD9;&#x4E9B;&#x673A;&#x5236;&#x7684;&#x5B58;&#x5728;&#xFF0C;&#x624D;&#x8D4B;&#x4E88;Java&#x5F3A;&#x5927;&#x7684;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7684;&#x80FD;&#x529B;&#x3002;&#x672C;&#x7AE0;&#x8BB2;&#x8FF0;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5;&#x3001;&#x5177;&#x6709;&#x591A;&#x7EE7;&#x627F;&#x7279;&#x6027;&#x7684;&#x63A5;&#x53E3;&#x548C;&#x5185;&#x90E8;&#x7C7B;&#x3002;</p>
</blockquote>
<p>&#x672C;&#x7AE0;&#x8981;&#x70B9;&#xFF08;&#x5DF2;&#x638C;&#x63E1;&#x7684;&#x5728;&#x65B9;&#x6846;&#x4E2D;&#x6253;&#x94A9;&#xFF09;</p>
<blockquote>
<p>&#x719F;&#x6089;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x4F7F;&#x7528;</p>
<p>&#x638C;&#x63E1;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5;</p>
<p>&#x638C;&#x63E1;&#x62BD;&#x8C61;&#x7C7B;&#x5B9E;&#x4F8B;&#x7684;&#x5E94;&#x7528;</p>
<p>&#x638C;&#x63E1;&#x63A5;&#x53E3;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5;</p>
<p>&#x719F;&#x6089;Java 8&#x4E2D;&#x63A5;&#x53E3;&#x7684;&#x65B0;&#x7279;&#x6027;</p>
<p>&#x719F;&#x6089;&#x63A5;&#x53E3;&#x5B9E;&#x4F8B;&#x7684;&#x5E94;&#x7528;</p>
<p>&#x719F;&#x6089;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x4F7F;&#x7528;</p>
</blockquote>
<p>&#x5728;&#x524D;&#x9762;&#x7684;&#x7AE0;&#x8282;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x53CD;&#x590D;&#x5F3A;&#x8C03;&#x4E00;&#x4E2A;&#x6982;&#x5FF5;&#xFF1A;&#x5728;Java&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7F16;&#x7A0B;&#x9886;&#x57DF;&#xFF0C;&#x4E00;&#x5207;&#x90FD;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x4E14;&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x662F;&#x901A;&#x8FC7;&#x201C;&#x7C7B;&#x201D;&#x6765;&#x63CF;&#x8FF0;&#x7684;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5E76;&#x4E0D;&#x662F;&#x6240;&#x6709;&#x7684;&#x7C7B;&#x90FD;&#x662F;&#x6765;&#x63CF;&#x8FF0;&#x5BF9;&#x8C61;&#x7684;&#x3002;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x7C7B;&#x6CA1;&#x6709;&#x8DB3;&#x591F;&#x7684;&#x4FE1;&#x606F;&#x6765;&#x63CF;&#x8FF0;&#x4E00;&#x4E2A;&#x5177;&#x4F53;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x5176;&#x4ED6;&#x5177;&#x4F53;&#x7684;&#x7C7B;&#x6765;&#x652F;&#x6491;&#x5B83;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x6837;&#x7684;&#x7C7B;&#x6211;&#x4EEC;&#x79F0;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#x3002;&#x6BD4;&#x5982;new Person( )&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x4E2A;&#x201C;&#x4EBA;&#x7C7B;&#x201D;&#x2014;&#x2014;Person( )&#x5177;&#x4F53;&#x957F;&#x6210;&#x4EC0;&#x4E48;&#x6837;&#x5B50;&#xFF0C;&#x6211;&#x4EEC;&#x5E76;&#x4E0D;&#x77E5;&#x9053;&#x3002;&#x4ED6;/&#x5979;&#x6CA1;&#x6709;&#x4E00;&#x4E2A;&#x5177;&#x4F53;&#x4EBA;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x66F4;&#x4E3A;&#x5177;&#x4F53;&#x7684;&#x7C7B;&#xFF0C;&#x5982;&#x5B66;&#x751F;&#x3001;&#x5DE5;&#x4EBA;&#x6216;&#x8001;&#x5E08;&#x7C7B;&#xFF0C;&#x6765;&#x5BF9;&#x5B83;&#x8FDB;&#x884C;&#x7279;&#x5B9A;&#x7684;&#x201C;&#x5177;&#x4F53;&#x5316;&#x201D;&#xFF0C;&#x6211;&#x4EEC;&#x624D;&#x77E5;&#x9053;&#x8FD9;&#x4EBA;&#x957F;&#x6210;&#x5565;&#x6837;&#x3002;
<a id="1"></a></p>
<h3 id="91-&#x62BD;&#x8C61;&#x7C7B;">9.1 &#x62BD;&#x8C61;&#x7C7B;</h3>
<h4 id="911-&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x5B9A;&#x4E49;">9.1.1 &#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x5B9A;&#x4E49;</h4>
<p>Java&#x4E2D;&#x6709;&#x4E00;&#x79CD;&#x7C7B;&#xFF0C;&#x6D3E;&#x751F;&#x51FA;&#x5F88;&#x591A;&#x5B50;&#x7C7B;&#xFF0C;&#x800C;&#x81EA;&#x8EAB;&#x662F;&#x4E0D;&#x80FD;&#x7528;&#x6765;&#x4EA7;&#x751F;&#x5BF9;&#x8C61;&#x7684;&#xFF0C;&#x8FD9;&#x79CD;&#x7C7B;&#x79F0;&#x4E3A;&#x201C;&#x62BD;&#x8C61;&#x7C7B;&#x201D;&#x3002;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x4F5C;&#x7528;&#x6709;&#x70B9;&#x7C7B;&#x4F3C;&#x4E8E;&#x201C;&#x6A21;&#x677F;&#x201D;&#xFF0C;&#x5176;&#x76EE;&#x7684;&#x662F;&#x8981;&#x8BBE;&#x8BA1;&#x8005;&#x4F9D;&#x636E;&#x5B83;&#x7684;&#x683C;&#x5F0F;&#x6765;&#x4FEE;&#x6539;&#x5E76;&#x521B;&#x5EFA;&#x65B0;&#x7684;&#x5B50;&#x7C7B;&#x3002;</p>
<p>&#x62BD;&#x8C61;&#x7C7B;&#x5B9E;&#x9645;&#x4E0A;&#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x7C7B;&#xFF0C;&#x53EA;&#x662F;&#x4E0E;&#x4E4B;&#x524D;&#x7684;&#x666E;&#x901A;&#x7C7B;&#x76F8;&#x6BD4;&#xFF0C;&#x5185;&#x90E8;&#x65B0;&#x589E;&#x4E86;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x3002;&#x6240;&#x8C13;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x5C31;&#x662F;&#x53EA;&#x58F0;&#x660E;&#x800C;&#x672A;&#x5B9E;&#x73B0;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x6240;&#x6709;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x5FC5;&#x987B;&#x4F7F;&#x7528;abstract&#x5173;&#x952E;&#x5B57;&#x58F0;&#x660E;&#xFF0C;&#x800C;&#x5305;&#x542B;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x7C7B;&#x5C31;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x4E5F;&#x5FC5;&#x987B;&#x4F7F;&#x7528;abstract class&#x58F0;&#x660E;&#x3002;</p>
<p>&#x62BD;&#x8C61;&#x7C7B;&#x5B9A;&#x4E49;&#x89C4;&#x5219;&#x5982;&#x4E0B;&#x3002;&#x62BD;&#x8C61;&#x7C7B;&#x548C;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x90FD;&#x5FC5;&#x987B;&#x7528;abstract&#x5173;&#x952E;&#x5B57;&#x6765;&#x4FEE;&#x9970;&#x3002;&#x62BD;&#x8C61;&#x7C7B;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x5B9E;&#x4F8B;&#x5316;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x7528;new&#x5173;&#x952E;&#x5B57;&#x53BB;&#x4EA7;&#x751F;&#x5BF9;&#x8C61;&#x3002;&#x5728;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#x65F6;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x53EA;&#x9700;&#x58F0;&#x660E;&#xFF0C;&#x800C;&#x65E0;&#x9700;&#x5B9E;&#x73B0;&#x3002;&#x542B;&#x6709;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x7C7B;&#x5FC5;&#x987B;&#x88AB;&#x58F0;&#x660E;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x5B50;&#x7C7B;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x6240;&#x6709;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x540E;&#xFF0C;&#x624D;&#x80FD;&#x4E0D;&#x53EB;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x4ECE;&#x800C;&#x53EF;&#x4EE5;&#x88AB;&#x5B9E;&#x4F8B;&#x5316;&#xFF0C;&#x5426;&#x5219;&#x8FD9;&#x4E2A;&#x5B50;&#x7C7B;&#x8FD8;&#x662F;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">abstract</span> <span class="token keyword">class</span> &#x7C7B;&#x540D;&#x79F0;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token comment">// &#x5B9A;&#x4E49;&#x62BD;&#x8C61;&#x7C7B;</span>
<span class="token punctuation">{</span>&#x3000; &#x58F0;&#x660E;&#x6570;&#x636E;&#x6210;&#x5458; &#xFF1B;
&#x3000; &#x8BBF;&#x95EE;&#x6743;&#x9650; &#x8FD4;&#x56DE;&#x503C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; &#x65B9;&#x6CD5;&#x540D;&#x79F0;&#xFF08;&#x53C2;&#x6570;&#x2026;&#xFF09;
&#x3000; <span class="token punctuation">{</span>&#x3000;&#x3000;&#x3000;
     <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x822C;&#x65B9;&#x6CD5;</span>
&#x3000;  &#xFF5D;&#x3000; 
<span class="token keyword">abstract</span> &#x8FD4;&#x56DE;&#x503C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; &#x65B9;&#x6CD5;&#x540D;&#x79F0;&#xFF08;&#x53C2;&#x6570;&#x2026;&#xFF09;&#xFF1B;&#x3000; 
<span class="token comment">// &#x5B9A;&#x4E49;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x91CC;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;&#x4F53;&#x3000;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4F8B;&#x5982;&#x4EE5;&#x4E0B;&#x5F62;&#x5F0F;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Book</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;</span>
<span class="token punctuation">{</span>&#x3000;&#x3000; 
    <span class="token keyword">private</span> <span class="token class-name">String</span> title <span class="token operator">=</span> <span class="token string">&quot;Java&#x5F00;&#x53D1;&quot;</span> <span class="token punctuation">;</span> <span class="token comment">// &#x5C5E;&#x6027;&#x3000; </span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#x3000; 
    <span class="token punctuation">{</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;
         <span class="token comment">// &#x666E;&#x901A;&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x201C;{}&#x201D;&#x8868;&#x793A;&#x6709;&#x65B9;&#x6CD5;&#x4F53;&#x3000;&#x3000; </span>
          <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>title<span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000; 
          <span class="token punctuation">}</span>
 &#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
 &#x3000;&#x3000;  <span class="token comment">// &#x6CA1;&#x6709;&#x65B9;&#x6CD5;&#x4F53;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
 <span class="token punctuation">}</span>
</code></pre>
<p>&#x7531;&#x4E0A;&#x4F8B;&#x53EF;&#x77E5;&#xFF0C;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x5B9A;&#x4E49;&#x53EA;&#x662F;&#x6BD4;&#x666E;&#x901A;&#x7C7B;&#x591A;&#x4E86;&#x4E00;&#x4E9B;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x5B9A;&#x4E49;&#x800C;&#x5DF2;&#x3002;&#x867D;&#x7136;&#x5B9A;&#x4E49;&#x4E86;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x4F46;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#x5374;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x3002;</p>
<pre class="language-"><code class="lang-java">   <span class="token class-name">Book</span> book <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Book</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000;&#x3000;<span class="token comment">// &#x9519;&#x8BEF;: Book&#x662F;&#x62BD;&#x8C61;&#x7684;; &#x65E0;&#x6CD5;&#x5B9E;&#x4F8B;&#x5316;</span>
</code></pre>
<h4 id="912-&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x4F7F;&#x7528;">9.1.2 &#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x4F7F;&#x7528;</h4>
<p>&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x7C7B;&#x53EF;&#x4EE5;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x7C7B;&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x6CA1;&#x6709;&#x65B9;&#x6CD5;&#x4F53;&#xFF0C;&#x6CA1;&#x6709;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x65B9;&#x6CD5;&#x65E0;&#x6CD5;&#x4F7F;&#x7528;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x5BF9;&#x4E8E;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x4F7F;&#x7528;&#x539F;&#x5219;&#x5982;&#x4E0B;&#x3002;</p>
<blockquote>
<p>&#x62BD;&#x8C61;&#x7C7B;&#x5FC5;&#x987B;&#x6709;&#x5B50;&#x7C7B;&#xFF0C;&#x5B50;&#x7C7B;&#x4F7F;&#x7528;extends&#x7EE7;&#x627F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x4E00;&#x4E2A;&#x5B50;&#x7C7B;&#x53EA;&#x80FD;&#x591F;&#x7EE7;&#x627F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x3002;</p>
<p>&#x4EA7;&#x751F;&#x5BF9;&#x8C61;&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x62BD;&#x8C61;&#x7C7B;&#x4E4B;&#x4E2D;&#x7684;&#x5168;&#x90E8;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x53EA;&#x6709;&#x6240;&#x6709;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x4E0D;&#x518D;&#x62BD;&#x8C61;&#x4E86;&#xFF0C;&#x505A;&#x5B9E;&#x5728;&#x4E86;&#xFF0C;&#x624D;&#x80FD;&#x4F9D;&#x636E;&#x7C7B;&#xFF08;&#x56FE;&#x7EB8;&#xFF09;&#xFF0C;&#x4EA7;&#x751F;&#x5BF9;&#x8C61;&#xFF08;&#x5177;&#x4F53;&#x7684;&#x4EA7;&#x54C1;&#xFF09;&#x3002;</p>
<p>&#x5982;&#x679C;&#x60F3;&#x8981;&#x5B9E;&#x4F8B;&#x5316;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5B50;&#x7C7B;&#x8FDB;&#x884C;&#x5BF9;&#x8C61;&#x7684;&#x5411;&#x4E0A;&#x8F6C;&#x578B;&#x6765;&#x5B8C;&#x6210;&#x3002;</p>
</blockquote>
<h3 id="&#x63D0;&#x793A;">&#x63D0;&#x793A;</h3>
<p>&#x5728;Java&#x4E2D;&#xFF0C;&#x5F53;&#x5B50;&#x7C7B;&#x7EE7;&#x627F;&#x7236;&#x7C7B;&#x65F6;&#xFF0C;&#x5B50;&#x7C7B;&#x53EF;&#x7531;&#x6B64;&#x5F97;&#x5230;&#x7236;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x4F46;&#x4E0D;&#x613F;&#x201C;&#x58A8;&#x5B88;&#x6210;&#x89C4;&#x201D;&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x53EF;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x91CD;&#x65B0;&#x6539;&#x5199;&#x7EE7;&#x627F;&#x4E8E;&#x7236;&#x7C7B;&#x7684;&#x540C;&#x540D;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x79F0;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x4E3A;&#x8986;&#x76D6;&#x91CD;&#x5199;&#xFF0C;&#x7B80;&#x79F0;&#x8986;&#x5199;&#xFF08;override&#xFF09;&#x3002;</p>
<p>&#x4ECE;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x8BBE;&#x8BA1;&#x7406;&#x5FF5;&#x53EF;&#x77E5;&#xFF0C;&#x62BD;&#x8C61;&#x7C7B;&#x751F;&#x6765;&#x5C31;&#x662F;&#x88AB;&#x7EE7;&#x627F;&#x7684;&#x3002;&#x5728;&#x5176;&#x5185;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x901A;&#x5E38;&#x662F;&#x6CA1;&#x6709;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x6709;&#x4E86;&#x4E5F;&#x6CA1;&#x7528;&#xFF0C;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x672C;&#x610F;&#x5C31;&#x662F;&#x671F;&#x671B;&#x5176;&#x201C;&#x5B50;&#x5B59;&#x540E;&#x4EE3;&#x201D;&#x7C7B;&#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x8D4B;&#x4E88;&#x65B0;&#x7684;&#x5185;&#x6DB5;&#x3002;&#x8FD9;&#x6837;&#x4E00;&#x6765;&#xFF0C;&#x867D;&#x7136;&#x5728;Java&#x82F1;&#x6587;&#x6587;&#x6863;&#x4E2D;&#x4F9D;&#x7136;&#x7528;&#x201C;override&#x201D;&#x6765;&#x8868;&#x660E;&#x5B50;&#x7C7B;&#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x6765;&#x81EA;&#x7236;&#x7C7B;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x5982;&#x679C;&#x8FD8;&#x5C06;&#x201C;override&#x201D;&#x7FFB;&#x8BD1;&#x4E3A;&#x201C;&#x8986;&#x5199;&#x201D;&#xFF0C;&#x5C31;&#x8FBE;&#x4E0D;&#x5230;&#x201C;&#x4FE1;&#x8FBE;&#x96C5;&#x201D;&#x7684;&#x8981;&#x6C42;&#x3002;</p>
<p>&#x516D;&#x7956;&#x60E0;&#x80FD;&#x5927;&#x5E08;&#x6709;&#x53E5;&#x540D;&#x8A00;&#xFF1A;&#x201C;&#x672C;&#x6765;&#x65E0;&#x4E00;&#x7269;&#xFF0C;&#x4F55;&#x5904;&#x60F9;&#x5C18;&#x57C3;&#x3002;&#x201D;</p>
<p>&#x5728;&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x8BF4;&#x4E00;&#x53E5;&#xFF1A;&#x201C;&#x672C;&#x65E0;&#x65B9;&#x6CD5;&#x4F53;&#xFF0C;&#x4F55;&#x5904;&#x6765;&#x8986;&#x5199;&#x3002;&#x201D;</p>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x672C;&#x4E66;&#x4E2D;&#xFF0C;&#x5BF9;&#x62BD;&#x8C61;&#x7C7B;&#x548C;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x5176;&#x5B50;&#x7C7B;&#x4E2D;&#x7ED9;&#x4E88;&#x5177;&#x4F53;&#x5B9A;&#x4E49;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x7528;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#x800C;&#x975E;&#x201C;&#x8986;&#x76D6;&#x201D;&#x6765;&#x63CF;&#x8FF0;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x3002;&#x7528;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#xFF0C;&#x5C06;&#x6765;&#x81EA;&#x7236;&#x7C7B;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x201C;&#x7ED9;&#x4E88;&#x201D;&#x751F;&#x547D;&#x3002;&#x8FD9;&#x6837;&#x53EF;&#x80FD;&#x66F4;&#x6709;&#x97F5;&#x610F;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-1 &#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x7528;&#x6CD5;&#x6848;&#x4F8B;&#xFF08;AbstractClassDemo.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Person</span>&#x3000;&#x3000;  <span class="token comment">//&#x5B9A;&#x4E49;&#x4E00;&#x62BD;&#x8C61;&#x7C7B;Person</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token class-name">String</span> name <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">int</span> age<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token class-name">String</span> occupation <span class="token punctuation">;</span>&#x3000;
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token class-name">String</span> <span class="token function">talk</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token comment">// &#x58F0;&#x660E;&#x4E00;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;talk( )</span>
&#x3000;<span class="token punctuation">}</span>  
&#x3000;<span class="token keyword">class</span> <span class="token class-name">Student</span> <span class="token keyword">extends</span> <span class="token class-name">Person</span>&#x3000; <span class="token comment">// Student&#x7C7B;&#x7EE7;&#x627F;&#x81EA;Person&#x7C7B;</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token class-name">Student</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">,</span><span class="token keyword">int</span> age<span class="token punctuation">,</span><span class="token class-name">String</span> occupation<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">=</span> age <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">this</span><span class="token punctuation">.</span>occupation <span class="token operator">=</span> occupation <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; 
&#x3000;&#x3000; <span class="token annotation punctuation">@Override</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">talk</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>&#x3000;<span class="token comment">// &#x5B9E;&#x73B0;talk( )&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">return</span> <span class="token string">&quot;&#x5B66;&#x751F;&#x2014;&#x2014;&amp;gt;&#x59D3;&#x540D;&#xFF1A;&quot;</span> <span class="token operator">+</span> name<span class="token operator">+</span><span class="token string">&quot;&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;&quot;</span> <span class="token operator">+</span> age<span class="token operator">+</span><span class="token string">&quot;&#xFF0C;&#x804C;&#x4E1A;&#xFF1A;&quot;</span> <span class="token operator">+</span> occupation <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">Worker</span> <span class="token keyword">extends</span> <span class="token class-name">Person</span>&#x3000; <span class="token comment">// Worker&#x7C7B;&#x7EE7;&#x627F;&#x81EA;Person&#x7C7B;</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token class-name">Worker</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">,</span><span class="token keyword">int</span> age<span class="token punctuation">,</span><span class="token class-name">String</span> occupation<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000; <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000; <span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">=</span> age <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000; <span class="token keyword">this</span><span class="token punctuation">.</span>occupation <span class="token operator">=</span> occupation <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">talk</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#x3000;  <span class="token comment">// &#x5B9E;&#x73B0;talk( )&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000; <span class="token keyword">return</span> <span class="token string">&quot;&#x5DE5;&#x4EBA;&#x2014;&#x2014;&amp;gt;&#x59D3;&#x540D;&#xFF1A;&quot;</span> <span class="token operator">+</span> name <span class="token operator">+</span> <span class="token string">&quot;,&#x5E74;&#x9F84;&#xFF1A;&quot;</span> <span class="token operator">+</span> age  <span class="token operator">+</span> <span class="token string">&quot;,&#x804C;&#x4E1A;:&quot;</span> <span class="token operator">+</span> occupation <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AbstractClassDemo</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000; <span class="token class-name">Student</span> s <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Student</span><span class="token punctuation">(</span><span class="token string">&quot;&#x5F20;&#x4E09;&quot;</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token string">&quot;&#x5B66;&#x751F;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//&#x521B;&#x5EFA;Student&#x7C7B;&#x5BF9;&#x8C61;s</span>
&#x3000;&#x3000;&#x3000; <span class="token class-name">Worker</span> w <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Worker</span><span class="token punctuation">(</span><span class="token string">&quot;&#x674E;&#x56DB;&quot;</span><span class="token punctuation">,</span>
<span class="token punctuation">,</span><span class="token string">&quot;&#x5DE5;&#x4EBA;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//&#x521B;&#x5EFA;Worker&#x7C7B;&#x5BF9;&#x8C61;w</span>
&#x3000;&#x3000;&#x3000; <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>s<span class="token punctuation">.</span><span class="token function">talk</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000; <span class="token comment">//&#x8C03;&#x7528;&#x88AB;&#x5B9E;&#x73B0;&#x7684;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;&#x3000; <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>w<span class="token punctuation">.</span><span class="token function">talk</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;</p>
<p>&#x7B2C;01~07&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;Person&#x7684;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5728;Person&#x4E2D;&#x58F0;&#x660E;&#x4E86;3&#x4E2A;&#x5C5E;&#x6027;&#x548C;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x2014;&#x2014;talk( )&#x3002;</p>
<p>&#x7B2C;08~22&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;Student&#x7C7B;&#xFF0C;&#x6B64;&#x7C7B;&#x7EE7;&#x627F;&#x81EA;Person&#x7C7B;&#xFF0C;&#x56E0;&#x4E3A;&#x6B64;&#x7C7B;&#x4E0D;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x201C;&#x5B9E;&#x73B0;&#x201D;Person&#x7C7B;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x2014;&#x2014;talk( )&#x3002;</p>
<p>&#x7C7B;&#x4F3C;&#x7684;&#xFF0C;&#x7B2C;23~35&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;Worker&#x7C7B;&#xFF0C;&#x6B64;&#x7C7B;&#x7EE7;&#x627F;&#x81EA;Person&#x7C7B;&#xFF0C;&#x56E0;&#x4E3A;&#x6B64;&#x7C7B;&#x4E0D;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x201C;&#x5B9E;&#x73B0;&#x201D;Person&#x7C7B;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x2014;&#x2014;talk( )&#x3002;</p>
<p>&#x7B2C;40&#x884C;&#x548C;&#x7B2C;41&#x884C;&#x5206;&#x522B;&#x5B9E;&#x4F8B;&#x5316;Student&#x7C7B;&#x4E0E;Worker&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x8C03;&#x7528;&#x5404;&#x81EA;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x521D;&#x59CB;&#x5316;&#x7C7B;&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x56E0;&#x4E3A;Student&#x7C7B;&#x4E0E;Worker&#x7C7B;&#x7EE7;&#x627F;&#x81EA;Person&#x7C7B;&#xFF0C;&#x6240;&#x4EE5;Person&#x7C7B;&#x7684;&#x6570;&#x636E;&#x6210;&#x5458;name&#x3001;age&#x548C;occupation&#xFF0C;&#x4E5F;&#x4F1A;&#x81EA;&#x52A8;&#x7EE7;&#x627F;&#x5230;Student&#x7C7B;&#x4E0E;Worker&#x7C7B;&#x3002;</p>
<p>&#x56E0;&#x6B64;&#x8FD9;&#x4E24;&#x4E2A;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF0C;&#x9700;&#x8981;&#x521D;&#x59CB;&#x5316;&#x8FD9;3&#x4E2A;&#x6570;&#x636E;&#x6210;&#x5458;&#x3002;&#x7B2C;42&#x884C;&#x548C;&#x7B2C;43&#x884C;&#x5206;&#x522B;&#x8C03;&#x7528;&#x5404;&#x81EA;&#x7C7B;&#x4E2D;&#x88AB;&#x5B9E;&#x73B0;&#x7684;talk( )&#x65B9;&#x6CD5;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x53EF;&#x4EE5;&#x770B;&#x5230;Student&#x548C;Worker&#x4E24;&#x4E2A;&#x5B50;&#x7C7B;&#x90FD;&#x5206;&#x522B;&#x6309;&#x5404;&#x81EA;&#x7684;&#x8981;&#x6C42;&#xFF0C;&#x5728;&#x5B50;&#x7C7B;&#x5B9E;&#x73B0;&#x4E86;talk( )&#x65B9;&#x6CD5;&#x3002;&#x4E0A;&#x9762;&#x7684;&#x7A0B;&#x5E8F;&#x53EF;&#x7531;&#x4E0B;&#x56FE;&#x8868;&#x793A;&#x3002;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x7279;&#x5F81;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>&#xFF08;1&#xFF09;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x53EF;&#x4EE5;&#x62E5;&#x6709;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x4E0E;&#x4E00;&#x822C;&#x7C7B;&#x76F8;&#x540C;&#xFF0C;&#x62BD;&#x8C61;&#x7C7B;&#x4E5F;&#x53EF;&#x4EE5;&#x62E5;&#x6709;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x4E9B;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x5FC5;&#x987B;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x88AB;&#x8C03;&#x7528;&#xFF0C;&#x5E76;&#x4E14;&#x5B50;&#x7C7B;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x7684;&#x65F6;&#x5019;&#x4F9D;&#x7136;&#x6EE1;&#x8DB3;&#x7C7B;&#x7EE7;&#x627F;&#x7684;&#x5173;&#x7CFB;&#xFF0C;&#x5148;&#x9ED8;&#x8BA4;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x540E;&#x518D;&#x8C03;&#x7528;&#x5B50;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF0C;&#x6BD5;&#x7ADF;&#x62BD;&#x8C61;&#x7C7B;&#x4E4B;&#x4E2D;&#x8FD8;&#x662F;&#x5B58;&#x5728;&#x5C5E;&#x6027;&#x7684;&#xFF0C;&#x4F46;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x65E0;&#x6CD5;&#x88AB;&#x5916;&#x90E8;&#x7C7B;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x8C03;&#x7528;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-2 &#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x7684;&#x5B9A;&#x4E49;&#x4F7F;&#x7528;&#xFF08;AbstractConstructor.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000; <span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Person</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token comment">//&#x5B9A;&#x4E49;&#x4E00;&#x62BD;&#x8C61;&#x7C7B;Person</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;<span class="token class-name">String</span> name <span class="token punctuation">;</span>&#x3000;&#x3000;  
&#x3000;&#x3000;<span class="token keyword">int</span> age <span class="token punctuation">;</span>
&#x3000;&#x3000;<span class="token class-name">String</span> occupation <span class="token punctuation">;</span>
&#x3000;&#x3000;<span class="token keyword">public</span> <span class="token class-name">Person</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">,</span><span class="token keyword">int</span> age<span class="token punctuation">,</span><span class="token class-name">String</span> occupation<span class="token punctuation">)</span>  <span class="token comment">//&#x5B9A;&#x4E49;&#x6784;&#x9020;&#x51FD;&#x6570;</span>
&#x3000;&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">=</span> age <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">this</span><span class="token punctuation">.</span>occupation <span class="token operator">=</span> occupation <span class="token punctuation">;</span>
&#x3000;&#x3000;<span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token class-name">String</span> <span class="token function">talk</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000; <span class="token comment">//&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">Student</span> <span class="token keyword">extends</span> <span class="token class-name">Person</span>&#x3000;&#x3000;<span class="token comment">//&#x58F0;&#x660E;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x5B50;&#x7C7B;</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;<span class="token keyword">public</span> <span class="token class-name">Student</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">,</span><span class="token keyword">int</span> age<span class="token punctuation">,</span><span class="token class-name">String</span> occupation<span class="token punctuation">)</span>&#x3000; 
&#x3000;&#x3000;<span class="token punctuation">{</span>  <span class="token comment">// &#x5728;&#x8FD9;&#x91CC;&#x5FC5;&#x987B;&#x660E;&#x786E;&#x8C03;&#x7528;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;&#x3000;<span class="token keyword">super</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span>age<span class="token punctuation">,</span>occupation<span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;<span class="token punctuation">}</span>
&#x3000;&#x3000;<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">talk</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#x3000;&#x3000;&#x3000;&#x3000;  <span class="token comment">// &#x5B9E;&#x73B0;talk()&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;<span class="token keyword">return</span> <span class="token string">&quot;&#x5B66;&#x751F;&#x2014;&#x2014;&amp;gt;&#x59D3;&#x540D;&#xFF1A;&quot;</span> <span class="token operator">+</span> name <span class="token operator">+</span> <span class="token string">&quot;&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;&quot;</span> <span class="token operator">+</span> age <span class="token operator">+</span> <span class="token string">&quot;&#xFF0C;&#x804C;&#x4E1A;&#xFF1A;&quot;</span> <span class="token operator">+</span> occupation<span class="token punctuation">;</span>
&#x3000;&#x3000;<span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">AbstractConstructor</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> 
&#x3000;&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;<span class="token class-name">Student</span> s <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Student</span><span class="token punctuation">(</span><span class="token string">&quot;&#x5F20;&#x4E09;&quot;</span><span class="token punctuation">,</span><span class="token number">18</span><span class="token punctuation">,</span><span class="token string">&quot;&#x5B66;&#x751F;&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">;</span><span class="token comment">//&#x521B;&#x5EFA;&#x5BF9;&#x8C61;s</span>
&#x3000;&#x3000;&#x3000;<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>s<span class="token punctuation">.</span><span class="token function">talk</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>  <span class="token comment">//&#x8C03;&#x7528;&#x5B9E;&#x73B0;&#x7684;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;01~13&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;Person&#x7684;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5728;Person&#x4E2D;&#x58F0;&#x660E;&#x4E86;3&#x4E2A;&#x5C5E;&#x6027;&#x3001;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x548C;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x2014;&#x2014;talk( )&#x3002;</p>
<p>&#x7B2C;14~24&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;Student&#x7C7B;&#xFF0C;&#x6B64;&#x7C7B;&#x7EE7;&#x627F;&#x81EA;Person&#x7C7B;&#xFF0C;&#x56E0;&#x4E3A;&#x6B64;&#x7C7B;&#x4E0D;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x5B9E;&#x73B0;Person&#x7C7B;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x2014;&#x2014;talk( )&#x3002;</p>
<p>&#x7B2C;18&#x884C;&#xFF0C;&#x4F7F;&#x7528;super( )&#x65B9;&#x6CD5;&#xFF0C;&#x663E;&#x5F0F;&#x8C03;&#x7528;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x7B2C;29&#x884C;&#x5B9E;&#x4F8B;&#x5316;Student&#x7C7B;&#xFF0C;&#x5EFA;&#x7ACB;&#x5BF9;&#x8C61;s&#xFF0C;&#x5E76;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x521D;&#x59CB;&#x5316;&#x7C7B;&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x7B2C;30&#x884C;&#x8C03;&#x7528;&#x5B50;&#x7C7B;&#x4E2D;&#x5B9E;&#x73B0;&#x7684;talk( )&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x4ECE;&#x7A0B;&#x5E8F;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x62BD;&#x8C61;&#x7C7B;&#x4E5F;&#x53EF;&#x4EE5;&#x50CF;&#x666E;&#x901A;&#x7C7B;&#x4E00;&#x6837;&#xFF0C;&#x6709;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x3001;&#x4E00;&#x822C;&#x65B9;&#x6CD5;&#x548C;&#x5C5E;&#x6027;&#xFF0C;&#x66F4;&#x91CD;&#x8981;&#x7684;&#x662F;&#x8FD8;&#x53EF;&#x4EE5;&#x6709;&#x4E00;&#x4E9B;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x9700;&#x8981;&#x5B50;&#x7C7B;&#x53BB;&#x5B9E;&#x73B0;&#xFF0C;&#x800C;&#x4E14;&#x5728;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x58F0;&#x660E;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x540E;&#xFF0C;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x5FC5;&#x987B;&#x660E;&#x786E;&#x8C03;&#x7528;&#x3002;</p>
<p>&#xFF08;2&#xFF09;&#x62BD;&#x8C61;&#x7C7B;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;final&#x5B9A;&#x4E49;&#xFF0C;&#x56E0;&#x4E3A;&#x4F7F;&#x7528;final&#x5B9A;&#x4E49;&#x7684;&#x7C7B;&#x4E0D;&#x80FD;&#x6709;&#x5B50;&#x7C7B;&#xFF0C;&#x800C;&#x62BD;&#x8C61;&#x7C7B;&#x4F7F;&#x7528;&#x7684;&#x65F6;&#x5019;&#x5FC5;&#x987B;&#x6709;&#x5B50;&#x7C7B;&#xFF0C;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x77DB;&#x76FE;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6240;&#x4EE5;&#x62BD;&#x8C61;&#x7C7B;&#x4E0A;&#x4E0D;&#x80FD;&#x51FA;&#x73B0;final&#x5B9A;&#x4E49;&#x3002;</p>
<p>&#xFF08;3&#xFF09;&#x62BD;&#x8C61;&#x7C7B;&#x4E4B;&#x4E2D;&#x53EF;&#x4EE5;&#x6CA1;&#x6709;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x5373;&#x4FBF;&#x6CA1;&#x6709;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5176;&#x201C;&#x62BD;&#x8C61;&#x201D;&#x7684;&#x672C;&#x8D28;&#x4E0D;&#x4F1A;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF0C;&#x6240;&#x4EE5;&#x4E5F;&#x4E0D;&#x80FD;&#x591F;&#x76F4;&#x63A5;&#x5728;&#x5916;&#x90E8;&#x901A;&#x8FC7;&#x5173;&#x952E;&#x5B57;new&#x5B9E;&#x4F8B;&#x5316;&#x3002;
<a id="2"></a></p>
<h3 id="92-&#x63A5;&#x53E3;">9.2 &#x63A5;&#x53E3;</h3>
<p>9.2.1 &#x63A5;&#x53E3;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5;</p>
<p>&#x5BF9;C&#x8BED;&#x8A00;&#x6709;&#x6240;&#x4E86;&#x89E3;&#x7684;&#x8BFB;&#x8005;&#x5C31;&#x4F1A;&#x77E5;&#x9053;&#xFF0C;&#x5728;C&#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x6709;&#x79CD;&#x590D;&#x5408;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x2014;&#x2014;structure&#xFF08;&#x7ED3;&#x6784;&#x4F53;&#xFF09;&#xFF0C;&#x7ED3;&#x6784;&#x4F53;&#x53EF;&#x89C6;&#x4E3A;&#x7EAF;&#x7CB9;&#x662F;&#x628A;&#x4E00;&#x7CFB;&#x5217;&#x76F8;&#x5173;&#x6570;&#x636E;&#x6C47;&#x96C6;&#x5728;&#x4E00;&#x8D77;&#xFF08;the collections of data&#xFF09;&#xFF0C;&#x6BD4;&#x5982;&#x8BF4;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x628A;&#x201C;&#x73ED;&#x7EA7;&#x201D;&#x201C;&#x5B66;&#x53F7;&#x201D;&#x201C;&#x59D3;&#x540D;&#x201D;&#x201C;&#x6027;&#x522B;&#x201D;&#x201C;&#x6210;&#x7EE9;&#x201D;&#x7B49;&#x6570;&#x636E;&#x5C5E;&#x6027;&#xFF0C;&#x6784;&#x6210;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;&#x201C;&#x5B66;&#x751F;&#x201D;&#x7684;&#x7ED3;&#x6784;&#x4F53;&#x3002;</p>
<p>Java&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x628A;&#x5BF9;&#x6570;&#x636E;&#x7684;&#x901A;&#x7528;&#x64CD;&#x4F5C;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x65B9;&#x6CD5;&#xFF09;&#xFF0C;&#x6C47;&#x96C6;&#x5728;&#x4E00;&#x8D77;&#xFF08;the collections of common operation&#xFF09;&#xFF0C;&#x5F62;&#x6210;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF08;interface&#xFF09;&#xFF0C;&#x4EE5;&#x5F62;&#x6210;&#x5BF9;&#x7B97;&#x6CD5;&#x7684;&#x590D;&#x7528;&#x3002;</p>
<p>&#x6240;&#x8C13;&#x7B97;&#x6CD5;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x7CFB;&#x5217;&#x76F8;&#x5173;&#x64CD;&#x4F5C;&#x6307;&#x4EE4;&#x7684;&#x96C6;&#x5408;&#x3002;</p>
<p>&#x63A5;&#x53E3;&#xFF0C;&#x662F;Java&#x6240;&#x63D0;&#x4F9B;&#x7684;&#x53E6;&#x4E00;&#x79CD;&#x91CD;&#x8981;&#x6280;&#x672F;&#xFF0C;&#x5B83;&#x53EF;&#x89C6;&#x4E3A;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x7684;&#x7C7B;&#xFF0C;&#x5176;&#x7ED3;&#x6784;&#x548C;&#x62BD;&#x8C61;&#x7C7B;&#x975E;&#x5E38;&#x76F8;&#x4F3C;&#xFF0C;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x4E00;&#x79CD;&#x53D8;&#x4F53;&#x3002;</p>
<p>&#x5728;Java 8&#x4E4B;&#x524D;&#xFF0C;&#x63A5;&#x53E3;&#x7684;&#x4E00;&#x4E2A;&#x5173;&#x952E;&#x7279;&#x5F81;&#x662F;&#xFF0C;&#x5B83;&#x65E2;&#x4E0D;&#x5305;&#x542B;&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x4E5F;&#x4E0D;&#x5305;&#x542B;&#x6570;&#x636E;&#x3002;</p>
<p>&#x6362;&#x53E5;&#x8BDD;&#x8BF4;&#xFF0C;&#x63A5;&#x53E3;&#x5185;&#x5B9A;&#x4E49;&#x7684;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#xFF0C;&#x90FD;&#x9ED8;&#x8BA4;&#x4E3A;abstract&#xFF0C;&#x5373;&#x90FD;&#x662F;&#x201C;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x201D;&#x3002;</p>
<p>&#x73B0;&#x5728;&#xFF0C;&#x5728;Java 8&#x4E2D;&#xFF0C;&#x63A5;&#x53E3;&#x7684;&#x89C4;&#x5B9A;&#x6709;&#x6240;&#x677E;&#x52A8;&#xFF0C;&#x5B83;&#x5185;&#x90E8;&#x5141;&#x8BB8;&#x5305;&#x62EC;&#x6570;&#x636E;&#x6210;&#x5458;&#xFF0C;&#x4F46;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#x5FC5;&#x987B;&#x662F;&#x5E38;&#x91CF;&#xFF0C;&#x5176;&#x503C;&#x4E00;&#x65E6;&#x88AB;&#x521D;&#x59CB;&#x5316;&#x540E;&#xFF0C;&#x662F;&#x4E0D;&#x5141;&#x8BB8;&#x66F4;&#x6539;&#x7684;&#xFF0C;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#x6210;&#x5458;&#x901A;&#x5E38;&#x4E3A;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x7CFB;&#x7EDF;&#x4F1A;&#x81EA;&#x52A8;&#x628A;&#x201C;public &#x201D;&#x201C;static&#x201D;&#x201C;final&#x201D;&#x8FD9;3&#x4E2A;&#x5173;&#x952E;&#x5B57;&#x6DFB;&#x52A0;&#x5728;&#x53D8;&#x91CF;&#x524D;&#x9762;&#xFF0C;&#x5982;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#x6240;&#x793A;&#x3002;</p>
<p>public interface faceA{&#x3000; int NORTH = 1;}&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x7B49;&#x6548;&#x4E3A;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#x3002;</p>
<p>public interface faceA{&#x3000;public static final int NORTH = 1;}&#x63A5;&#x53E3;&#x7684;&#x8BBE;&#x8BA1;&#x5B97;&#x65E8;&#x5728;&#x4E8E;&#xFF0C;&#x5B9A;&#x4E49;&#x7531;&#x591A;&#x4E2A;&#x7EE7;&#x627F;&#x7C7B;&#x5171;&#x540C;&#x9075;&#x5B88;&#x7684; &#x201C;&#x5951;&#x7EA6;&#x201D;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x6210;&#x5458;&#xFF0C;&#x5176;&#x8BBF;&#x95EE;&#x7C7B;&#x578B;&#x90FD;&#x5FC5;&#x987B;&#x4E3A;public&#xFF0C;&#x5426;&#x5219;&#x4E0D;&#x80FD;&#x88AB;&#x7EE7;&#x627F;&#xFF0C;&#x5C31;&#x5931;&#x53BB;&#x4E86;&#x201C;&#x5951;&#x7EA6;&#x201D;&#x5185;&#x6DB5;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x5728;&#x63A5;&#x53E3;&#x4E2D;&#x6DFB;&#x52A0;&#x65B0;&#x65B9;&#x6CD5;&#x540E;&#x800C;&#x8981;&#x4FEE;&#x6539;&#x6240;&#x6709;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x662F;&#x4E3A;&#x4E86;&#x652F;&#x6301;Lambda&#x65B0;&#x7279;&#x6027;&#x7684;&#x5F15;&#x5165;&#xFF0C;&#x4ECE;JDK 8&#x5F00;&#x59CB;&#xFF0C;Java&#x7684;&#x63A5;&#x53E3;&#x4E5F;&#x653E;&#x5BBD;&#x4E86;&#x4E00;&#x4E9B;&#x9650;&#x5236;&#xFF0C;&#x63A5;&#x53E3;&#x4E2D;&#x8FD8;&#x53EF;&#x4EE5;&#x201C;&#x6709;&#x6761;&#x4EF6;&#x201D;&#x5730;&#x5BF9;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x5141;&#x8BB8;&#x5B9A;&#x4E49;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF08;&#x5373;default&#x65B9;&#x6CD5;&#xFF09;&#xFF0C;&#x4E5F;&#x53EF;&#x79F0;&#x4E3A;Defender&#x65B9;&#x6CD5;&#x3002;</p>
<p>default&#x65B9;&#x6CD5;&#x662F;&#x6307;&#xFF0C;&#x5141;&#x8BB8;&#x5728;&#x63A5;&#x53E3;&#x5185;&#x90E8;&#x5B9E;&#x73B0;&#x4E00;&#x4E9B;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5728;&#x63A5;&#x53E3;&#x4E2D;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x65B9;&#x6CD5;&#x4F53;&#xFF0C;&#x8FD9;&#x6253;&#x7834;&#x4E86;Java 8&#x7248;&#x672C;&#x4E4B;&#x524D;&#x5BF9;&#x63A5;&#x53E3;&#x7684;&#x8BED;&#x6CD5;&#x9650;&#x5236;&#xFF09;&#xFF0C;&#x4ECE;&#x800C;&#x4F7F;&#x5F97;&#x63A5;&#x53E3;&#x5728;&#x8FDB;&#x884C;&#x6269;&#x5C55;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E0D;&#x4F1A;&#x7834;&#x574F;&#x4E0E;&#x63A5;&#x53E3;&#x76F8;&#x5173;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#x4EE3;&#x7801;&#x3002;</p>
<p>&#x5728;Java&#x4E2D;&#x4F7F;&#x7528;interface&#x5173;&#x952E;&#x5B57;&#x6765;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x7684;&#x8BED;&#x6CD5;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>interface &#x63A5;&#x53E3;&#x540D;&#x79F0;&#x3000;// &#x5B9A;&#x4E49;&#x63A5;&#x53E3;{&#x3000; final &#x6570;&#x636E;&#x7C7B;&#x578B; &#x6210;&#x5458;&#x540D;&#x79F0; = &#x5E38;&#x91CF; &#xFF1B;&#x3000;// &#x6570;&#x636E;&#x6210;&#x5458;&#x5FC5;&#x987B;&#x8D4B;&#x521D;&#x503C;&#x3000; abstract &#x8FD4;&#x56DE;&#x503C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; &#x65B9;&#x6CD5;&#x540D;&#x79F0;&#xFF08;&#x53C2;&#x6570;&#x2026;&#xFF09;&#xFF1B;// &#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x6CA1;&#x6709;&#x65B9;&#x6CD5;&#x4F53;&#x3000; default  &#x8FD4;&#x56DE;&#x503C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; &#x65B9;&#x6CD5;&#x540D;&#x79F0;&#xFF08;&#x53C2;&#x6570;&#x2026;&#xFF09;// &#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF0C;&#x5305;&#x542B;&#x65B9;&#x6CD5;&#x4F53;&#x3000; {&#x3000;&#x3000;  &#x2026;&#x65B9;&#x6CD5;&#x4F53;&#x2026;&#x3000; }}&#x63A5;&#x53E3;&#x7684;&#x5B9A;&#x4E49;&#x8303;&#x4F8B;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">interface</span> <span class="token class-name">B</span>  <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;B</span>
<span class="token punctuation">{</span>&#x3000;&#x3000; 
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> INFO <span class="token operator">=</span> <span class="token string">&quot;Hello World .&quot;</span> <span class="token punctuation">;</span>&#x3000;<span class="token comment">// &#x5168;&#x5C40;&#x5E38;&#x91CF;&#xFF0C;public&#x3001;static&#x3001;final&#x53EF;&#x7701;&#x7565;&#x3000; </span>
    <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">// &#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x3000; </span>
    <span class="token keyword">default</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">otherprint</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token comment">// &#x5E26;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x3000; </span>
    <span class="token punctuation">{</span>&#x3000;&#x3000;&#x3000;&#x3000;  &#x3000;&#x3000;  
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;default methods!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;<span class="token comment">//&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x7684;&#x65B9;&#x6CD5;&#x4F53;&#x3000; </span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x867D;&#x7136;&#x5B9A;&#x4E49;&#x4E86;&#x63A5;&#x53E3;&#xFF0C;&#x4F46;&#x5728;&#x6240;&#x5B9A;&#x4E49;&#x7684;&#x63A5;&#x53E3;A&#x548C;&#x63A5;&#x53E3;B&#x4E2D;&#xFF0C;&#x56E0;&#x63A5;&#x53E3;&#x5185;&#x5B58;&#x5728;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x56E0;&#x6B64;&#x8FD9;&#x4E9B;&#x63A5;&#x53E3;&#x90FD;&#x4E0D;&#x80FD;&#x88AB;&#x7528;&#x6237;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#xFF0C;&#x5FC5;&#x987B;&#x5728;&#x5176;&#x5B50;&#x7C7B;&#x4E2D;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#x8FD9;&#x4E9B;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x628A;&#x201C;&#x62BD;&#x8C61;&#x7684;&#x201D;&#x65B9;&#x6CD5;&#x201C;&#x52A1;&#x5B9E;&#x201D;&#x4E86;&#xFF0C;&#x53D8;&#x4E3A;&#x5B9E;&#x5B9E;&#x5728;&#x5728;&#x7684;&#x53EF;&#x7528;&#x65B9;&#x6CD5;&#xFF0C;&#x624D;&#x53EF;&#x4EE5;&#x7528;&#x4E4B;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x3002;</p>
<p>9.2.2 &#x4F7F;&#x7528;&#x63A5;&#x53E3;&#x7684;&#x539F;&#x5219;&#x4F7F;&#x7528;&#x63A5;&#x53E3;&#x65F6;&#xFF0C;&#x6CE8;&#x610F;&#x9075;&#x5B88;&#x5982;&#x4E0B;&#x539F;&#x5219;&#x3002;</p>
<p>&#x63A5;&#x53E3;&#x5FC5;&#x987B;&#x6709;&#x5B50;&#x7C7B;&#xFF0C;&#x5B50;&#x7C7B;&#x4F9D;&#x9760;implements&#x5173;&#x952E;&#x5B57;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x63A5;&#x53E3;&#x7684;&#x5B50;&#x7C7B;&#xFF08;&#x5982;&#x679C;&#x4E0D;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#xFF09;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x4E4B;&#x4E2D;&#x7684;&#x5168;&#x90E8;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x624D;&#x80FD;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5229;&#x7528;&#x5B50;&#x7C7B;&#x5B9E;&#x73B0;&#x5BF9;&#x8C61;&#x7684;&#x5B9E;&#x4F8B;&#x5316;&#xFF0C;&#x63A5;&#x53E3;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x591A;&#x6001;&#x6027;&#x3002;</p>
<p>&#x63A5;&#x53E3;&#x4E0E;&#x4E00;&#x822C;&#x7C7B;&#x4E00;&#x6837;&#xFF0C;&#x672C;&#x8EAB;&#x4E5F;&#x62E5;&#x6709;&#x6570;&#x636E;&#x6210;&#x5458;&#x4E0E;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x6570;&#x636E;&#x6210;&#x5458;&#x4E00;&#x5B9A;&#x8981;&#x8D4B;&#x521D;&#x503C;&#xFF0C;&#x4E14;&#x6B64;&#x503C;&#x4E0D;&#x80FD;&#x518D;&#x66F4;&#x6539;&#xFF0C;&#x65B9;&#x6CD5;&#x4E5F;&#x5FC5;&#x987B;&#x662F;&#x201C;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x201D;&#x6216;default&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x4E5F;&#x6B63;&#x56E0;&#x4E3A;&#x63A5;&#x53E3;&#x5185;&#x7684;&#x65B9;&#x6CD5;&#x9664;default&#x65B9;&#x6CD5;&#x5916;&#x5FC5;&#x987B;&#x662F;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x6CA1;&#x6709;&#x5176;&#x4ED6;&#x4E00;&#x822C;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x683C;&#x5F0F;&#x4E2D;&#xFF0C;&#x58F0;&#x660E;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x5173;&#x952E;&#x5B57;abstract&#x662F;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#x7684;&#x3002;</p>
<p>&#x540C;&#x7406;&#xFF0C;&#x56E0;&#x63A5;&#x53E3;&#x7684;&#x6570;&#x636E;&#x6210;&#x5458;&#x5FC5;&#x987B;&#x8D4B;&#x521D;&#x503C;&#xFF0C;&#x4E14;&#x6B64;&#x503C;&#x4E0D;&#x80FD;&#x518D;&#x88AB;&#x66F4;&#x6539;&#xFF0C;&#x6240;&#x4EE5;&#x58F0;&#x660E;&#x6570;&#x636E;&#x6210;&#x5458;&#x7684;&#x5173;&#x952E;&#x5B57;final&#x4E5F;&#x53EF;&#x7701;&#x7565;&#x3002;</p>
<p>&#x7B80;&#x5199;&#x7684;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x8303;&#x4F8B;&#x5982;&#x4E0B;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">interface</span> <span class="token class-name">A</span>  <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</span>
<span class="token punctuation">{</span>&#x3000;&#x3000; 
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">String</span> INFO <span class="token operator">=</span> <span class="token string">&quot;Hello World .&quot;</span> <span class="token punctuation">;</span>&#x3000;<span class="token comment">// &#x5168;&#x5C40;&#x5E38;&#x91CF;&#x3000; </span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">// &#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x3000; </span>
    <span class="token keyword">default</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">otherprint</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#x3000; 
    <span class="token punctuation">{</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; 
        <span class="token comment">// &#x5E26;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x3000;&#x3000;  </span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;default methods!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000; 
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728;Java&#x4E2D;&#xFF0C;&#x7531;&#x4E8E;&#x7981;&#x6B62;&#x591A;&#x7EE7;&#x627F;&#xFF08;&#x901A;&#x4FD7;&#x6765;&#x8BB2;&#xFF0C;&#x5C31;&#x597D;&#x6BD4;&#x4E00;&#x4E2A;&#x201C;&#x513F;&#x5B50;&#x201D;&#x53EA;&#x80FD;&#x8BA4;&#x4E00;&#x4E2A;&#x201C;&#x8001;&#x7238;&#x201D;&#xFF09;&#xFF0C;&#x800C;&#x63A5;&#x53E3;&#x505A;&#x4E86;&#x4E00;&#x70B9;&#x53D8;&#x901A;&#xFF0C;&#x4E00;&#x4E2A;&#x5B50;&#x7C7B;&#x53EF;&#x4EE5;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x8FD9;&#x662F;&#x201C;&#x95F4;&#x63A5;&#x201D;&#x5B9E;&#x73B0;&#x591A;&#x7EE7;&#x627F;&#x7684;&#x4E00;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x8FD9;&#x4E5F;&#x662F;Java&#x8BBE;&#x8BA1;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x91CD;&#x8981;&#x73AF;&#x8282;&#x3002;</p>
<p>&#x65E2;&#x7136;&#x63A5;&#x53E3;&#x4E2D;&#x9664;&#x4E86;default&#x65B9;&#x6CD5;&#xFF0C;&#x53EA;&#x80FD;&#x6709;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x7C7B;&#x65B9;&#x6CD5;&#x53EA;&#x9700;&#x58F0;&#x660E;&#xFF0C;&#x800C;&#x65E0;&#x9700;&#x5B9A;&#x4E49;&#x5177;&#x4F53;&#x7684;&#x65B9;&#x6CD5;&#x4F53;&#xFF0C;&#x4E8E;&#x662F;&#x81EA;&#x7136;&#x53EF;&#x4EE5;&#x8054;&#x60F3;&#x5230;&#xFF0C;&#x63A5;&#x53E3;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x50CF;&#x4E00;&#x822C;&#x7C7B;&#x4E00;&#x6837;&#xFF0C;&#x7528;&#x5B83;&#x6765;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5229;&#x7528;&#x63A5;&#x53E3;&#x521B;&#x5EFA;&#x65B0;&#x7C7B;&#x7684;&#x8FC7;&#x7A0B;&#x79F0;&#x4E3A;&#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;&#xFF08;implementation&#xFF09;&#x3002;</p>
<p>&#x4EE5;&#x4E0B;&#x4E3A;&#x63A5;&#x53E3;&#x5B9E;&#x73B0;&#x7684;&#x8BED;&#x6CD5;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">class</span> &#x5B50;&#x7C7B;&#x540D;&#x79F0; <span class="token keyword">implements</span> &#x63A5;&#x53E3;<span class="token class-name">A</span><span class="token punctuation">,</span>&#x63A5;&#x53E3;<span class="token class-name">B</span>&#x2026;    <span class="token comment">// &#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;{&#x2026;}&#x8303;&#x4F8B;9-3 &#x5E26;default&#x65B9;&#x6CD5;&#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;&#xFF08;Interfacedefault.java&#xFF09;</span>
&#x3000;<span class="token keyword">interface</span> <span class="token class-name">InterfaceA</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</span>
&#x3000;<span class="token punctuation">{</span>&#x3000;
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">String</span> INFO <span class="token operator">=</span> <span class="token string">&quot;static final.&quot;</span> <span class="token punctuation">;</span> <span class="token comment">// &#x5168;&#x5C40;&#x5E38;&#x91CF;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token comment">// &#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; 
&#x3000;&#x3000; <span class="token keyword">default</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">otherprint</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>&#x3000;&#x3000;&#x3000;&#x3000;  <span class="token comment">// &#x5E26;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;print default1 methods InterfaceA!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;
&#x3000;<span class="token keyword">class</span> subClass <span class="token keyword">implements</span> <span class="token class-name">InterfaceA</span>&#x3000;&#x3000;  <span class="token comment">//&#x5B50;&#x7C7B;InterfaceA&#x5B9E;&#x73B0;&#x63A5;&#x53E3;InterfaceA</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;  <span class="token comment">//&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;print( )</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;print abstract methods InterfaceA!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>INFO<span class="token punctuation">)</span><span class="token punctuation">;</span>  
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Interfacedefault</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span> <span class="token punctuation">]</span> args<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  subClass subObj <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token function">subClass</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;  <span class="token comment">//&#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;</span>
&#x3000;&#x3000;&#x3000;  subObj<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;  <span class="token comment">//&#x8C03;&#x7528;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#x8FC7;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;&#x3000;  subObj<span class="token punctuation">.</span><span class="token function">otherprint</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">//&#x8C03;&#x7528;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">InterfaceA</span><span class="token punctuation">.</span>INFO<span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;<span class="token comment">//&#x8F93;&#x51FA;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x5E38;&#x91CF;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;01~10&#x884C;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;InterfaceA&#xFF0C;&#x5176;&#x4E2D;&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x9759;&#x6001;&#x53D8;&#x91CF;INFO&#x3001;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;print()&#x53CA;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;otherprint()&#x3002;</p>
<p>&#x7B2C;12~19&#x884C;&#x5B9A;&#x4E49;&#x5B50;&#x7C7B;subClass&#xFF0C;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;InterfaceA&#xFF0C;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#x4ECE;&#x63A5;&#x53E3;InterfaceA&#x7EE7;&#x627F;&#x800C;&#x6765;&#x7684;&#x65B9;&#x6CD5;print()&#x3002;</p>
<p>&#x7B2C;24&#x884C;&#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x8C03;&#x7528;&#x5728;&#x5B50;&#x7C7B;&#x5B9E;&#x73B0;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF08;&#x7B2C;25&#x884C;&#xFF09;&#x548C;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF08;&#x7B2C;26&#x884C;&#xFF09;&#xFF0C;&#x8F93;&#x51FA;&#x63A5;&#x53E3;InterfaceA&#x7684;&#x5E38;&#x91CF;INFO&#xFF08;&#x7B2C;27&#x884C;&#xFF09;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x4E0A;&#x4F8B;&#x4E2D;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x63A5;&#x53E3;&#x4E2D;&#x5B9A;&#x4E49;&#x5E38;&#x91CF;INFO&#xFF0C;&#x7701;&#x7565;&#x4E86;&#x5173;&#x952E;&#x8BCD;final&#xFF0C;&#x5B9A;&#x4E49;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;print()&#xFF1B;&#xFF0C;&#x4E5F;&#x7701;&#x7565;&#x4E86;Abstract&#xFF0C;&#x5B9A;&#x4E49;&#x5E26;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x7B2C;17&#x884C;&#x548C;&#x7B2C;27&#x884C;&#x5206;&#x522B;&#x5F15;&#x7528;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x5E38;&#x91CF;&#x3002;</p>
<p>&#x5728;Java 8&#x4E2D;&#xFF0C;&#x5141;&#x8BB8;&#x5728;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x4E2D;&#x53EA;&#x5B9A;&#x4E49;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x6CA1;&#x6709;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x4E0B;&#x9762;&#x4E3E;&#x4F8B;&#x8BF4;&#x660E;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-4 &#x4EC5;&#x6709;default&#x65B9;&#x6CD5;&#x63A5;&#x53E3;&#x7684;&#x4F7F;&#x7528;&#xFF08;InterfacedefaultOnly.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">interface</span> <span class="token class-name">InterfaceA</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</span>
&#x3000;<span class="token punctuation">{</span>&#x3000;
&#x3000;&#x3000; <span class="token keyword">default</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">otherprint</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>&#x3000;&#x3000;<span class="token comment">// &#x5E26;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;print default1 methods only in InterfaceA!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> subClass <span class="token keyword">implements</span> <span class="token class-name">InterfaceA</span>&#x3000;&#x3000; <span class="token comment">//&#x5B50;&#x7C7B;subClass&#x5B9E;&#x73B0;&#x63A5;&#x53E3;InterfaceA</span>
&#x3000;<span class="token punctuation">{</span>&#x3000;
&#x3000;&#x3000; <span class="token comment">//do nothing</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">InterfaceDefaultOnly</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span> <span class="token punctuation">]</span> args<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  subClass subObj <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token function">subClass</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;<span class="token comment">//&#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;&#x3000;</span>
&#x3000;&#x3000;&#x3000;  subObj<span class="token punctuation">.</span><span class="token function">otherprint</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">//&#x8C03;&#x7528;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x3000;&#x3000;  </span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;01~07&#x884C;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;InterfaceA&#xFF0C;&#x5176;&#x4E2D;&#x5B9A;&#x4E49;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;otherprint()&#x3002;</p>
<p>&#x7B2C;08~11&#x884C;&#x5B9A;&#x4E49;&#x5B50;&#x7C7B;subClass&#xFF0C;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;InterfaceA&#x3002;</p>
<p>&#x7B2C;16~17&#x884C;&#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;subObj&#xFF0C;&#x5E76;&#x8C03;&#x7528;&#x7531;&#x63A5;&#x53E3;InterfaceA&#x7EE7;&#x627F;&#x800C;&#x6765;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;otherprint()&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x7531;&#x4E8E;&#x63A5;&#x53E3;InterfaceA&#x4E2D;&#x5E76;&#x65E0;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x56E0;&#x6B64;&#x65E0;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x9700;&#x8981;&#x5728;&#x5B50;&#x7C7B;&#x4E2D;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#xFF0C;&#x6240;&#x4EE5;&#x5B50;&#x7C7B;subClass&#x7684;&#x4E3B;&#x4F53;&#x90E8;&#x5206;&#x4EC0;&#x4E48;&#x4E5F;&#x6CA1;&#x6709;&#x505A;&#xFF0C;&#x4F46;&#x8FD9;&#x90E8;&#x5206;&#x7684;&#x5DE5;&#x4F5C;&#x662F;&#x5FC5;&#x9700;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x63A5;&#x53E3;&#x662F;&#x4E0D;&#x80FD;&#xFF08;&#x901A;&#x8FC7;new&#x64CD;&#x4F5C;&#xFF09;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x7684;&#xFF0C;&#x5373;&#x4F7F;&#x5B50;&#x7C7B;subClass&#x4EC0;&#x4E48;&#x4E5F;&#x6CA1;&#x6709;&#x505A;&#xFF0C;&#x5176;&#x5B9E;&#x4E5F;&#x5B9E;&#x73B0;&#x4E86;&#x4E00;&#x4E2A;&#x529F;&#x80FD;&#xFF0C;&#x5373;&#x7531;subClass&#x53EF;&#x4EE5;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x63A5;&#x53E3;&#x4E0E;&#x62BD;&#x8C61;&#x7C7B;&#x76F8;&#x6BD4;&#xFF0C;&#x4E3B;&#x8981;&#x533A;&#x522B;&#x5C31;&#x5728;&#x4E8E;&#x5B50;&#x7C7B;&#x4E0A;&#xFF0C;&#x5B50;&#x7C7B;&#x7684;&#x7EE7;&#x627F;&#x4F53;&#x7CFB;&#x4E2D;&#xFF0C;&#x6C38;&#x8FDC;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x7236;&#x7C7B;&#xFF0C;&#x4F46;&#x5B50;&#x7C7B;&#x5374;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x53D8;&#x76F8;&#x5B8C;&#x6210;&#x201C;&#x591A;&#x7EE7;&#x627F;&#x201D;&#xFF0C;&#x5982;&#x4E0B;&#x4F8B;&#x6240;&#x793A;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-5 &#x5B50;&#x7C7B;&#x7EE7;&#x627F;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#x7684;&#x5E94;&#x7528;&#xFF08;InterfaceDemo.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">interface</span> faceA&#x3000; <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</span>
&#x3000;<span class="token punctuation">{</span>  
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> INFO <span class="token operator">=</span> <span class="token string">&quot;Hello World!&quot;</span> <span class="token punctuation">;</span> <span class="token comment">// &#x5168;&#x5C40;&#x5E38;&#x91CF;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>  <span class="token comment">// &#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">interface</span> faceB&#x3000;  <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</span>
&#x3000;<span class="token punctuation">{</span>&#x3000;
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">get</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> subClass <span class="token keyword">implements</span> faceA<span class="token punctuation">,</span>faceB 
&#x3000;<span class="token punctuation">{</span>&#x3000; <span class="token comment">// &#x4E00;&#x4E2A;&#x5B50;&#x7C7B;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x4E86;&#x4E24;&#x4E2A;&#x63A5;&#x53E3;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span> INFO <span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">get</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x4F60;&#x597D;&#xFF01;&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">InterfaceDemo</span>  
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span> args<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  subClass subObj <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token function">subClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token comment">// &#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;</span>
&#x3000;&#x3000;&#x3000;  
&#x3000;&#x3000;&#x3000;  faceA fa <span class="token operator">=</span> subObj <span class="token punctuation">;</span>&#x3000;<span class="token comment">// &#x4E3A;&#x7236;&#x63A5;&#x53E3;&#x5B9E;&#x4F8B;&#x5316;</span>
&#x3000;&#x3000;&#x3000;  fa<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  
&#x3000;&#x3000;&#x3000;  faceB fb <span class="token operator">=</span> subObj <span class="token punctuation">;</span>&#x3000;<span class="token comment">// &#x4E3A;&#x7236;&#x63A5;&#x53E3;&#x5B9E;&#x4F8B;&#x5316;</span>
&#x3000;&#x3000;&#x3000;  fb<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;01~05&#x884C;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;faceA&#xFF0C;&#x5176;&#x4E2D;&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x53D8;&#x91CF;INFO&#x548C;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;print()&#x3002;</p>
<p>&#x7B2C;06~09&#x884C;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;faceB&#xFF0C;&#x5E76;&#x5B9A;&#x4E49;&#x4E86;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;get( )&#x3002;</p>
<p>&#x7B2C;10~20&#x884C;&#x5B9A;&#x4E49;&#x5B50;&#x7C7B;subClass&#xFF0C;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;faceA&#x548C;faceB&#xFF0C;&#x5E76;&#x5206;&#x522B;&#x5BF9;&#x63A5;&#x53E3;faceA&#x548C;faceB&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x7531;&#x4E0A;&#x4F8B;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x63A5;&#x53E3;&#x4E0E;&#x62BD;&#x8C61;&#x7C7B;&#x76F8;&#x6BD4;&#xFF0C;&#x4E3B;&#x8981;&#x533A;&#x522B;&#x5C31;&#x5728;&#x4E8E;&#x5B50;&#x7C7B;&#x4E0A;&#xFF0C;&#x5B50;&#x7C7B;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x4F46;&#x5728;Java 8&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x7C7B;&#x5B9E;&#x73B0;&#x4E24;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x5373;&#x201C;&#x53D8;&#x76F8;&#x201D;&#x7684;&#x591A;&#x7EE7;&#x627F;&#xFF0C;&#x4F46;&#x662F;&#x82E5;&#x5176;&#x4E2D;&#x4E24;&#x4E2A;&#x63A5;&#x53E3;&#x4E2D;&#x90FD;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x540D;&#x5B57;&#x76F8;&#x540C;&#x7684;default&#x65B9;&#x6CD5;&#xFF0C;&#x5982;&#x4E0B;&#x4F8B;&#x4E2D;&#x7684;faceA&#x548C;faceB&#x4E2D;&#x6709;&#x540C;&#x540D;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;DefaultMethod( )&#xFF0C;&#x4F46;&#x65B9;&#x6CD5;&#x4F53;&#x4E0D;&#x540C;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-6 &#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x542B;&#x6709;&#x4E24;&#x4E2A;&#x76F8;&#x540C;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x540D;&#x7684;&#x63A5;&#x53E3;&#xFF08;Interfacsamedefaults.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">interface</span> faceA&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">//&#x5B9A;&#x4E49;&#x63A5;&#x53E3;faceA</span>
&#x3000;<span class="token punctuation">{</span>&#x3000;
&#x3000;&#x3000; <span class="token keyword">void</span> <span class="token function">someMethod</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">default</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token class-name">DefaultMethod</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token comment">//&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;Default method in the interface A&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">interface</span> faceB&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">//&#x5B9A;&#x4E49;&#x63A5;&#x53E3;faceB</span>
&#x3000;<span class="token punctuation">{</span>  
&#x3000;&#x3000; <span class="token keyword">default</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token class-name">DefaultMethod</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token comment">//&#x5B9A;&#x4E49;&#x63A5;&#x53E3;InterfaceB&#x4E2D;&#x540C;&#x540D;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;Default method in the interface B&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">DefaultMethodClass</span> <span class="token keyword">implements</span> faceA<span class="token punctuation">,</span>faceB  <span class="token comment">//&#x5B50;&#x7C7B;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;faceA&#x548C;faceB</span>
&#x3000;<span class="token punctuation">{</span>&#x3000;<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">someMethod</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">//&#x5B9E;&#x73B0;&#x63A5;&#x53E3;InterfaceA&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;Some method in the subclass&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;
&#x3000;&#x3000; <span class="token punctuation">}</span>&#x3000;
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Interfacsamedefaults</span> 
&#x3000;<span class="token punctuation">{</span>&#x3000;
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>&#x3000;
&#x3000;&#x3000;&#x3000;  <span class="token class-name">DefaultMethodClass</span> def <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DefaultMethodClass</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  def<span class="token punctuation">.</span><span class="token function">someMethod</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000; <span class="token comment">//&#x8C03;&#x7528;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000;&#x3000;  def<span class="token punctuation">.</span><span class="token class-name">DefaultMethod</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;&#x3000;&#x3000;<span class="token comment">//&#x8C03;&#x7528;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x7A0B;&#x5E8F;&#x5E76;&#x8FD0;&#x884C;&#xFF0C;&#x7F16;&#x8BD1;&#x5E76;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x4EE3;&#x7801;&#x7B2C;01~08&#x884C;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;faceA&#xFF0C;&#x5176;&#x4E2D;&#x5B9A;&#x4E49;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;someMethod( )&#x548C;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;DefaultMethod( )&#xFF0C;&#x8BF7;&#x6CE8;&#x610F;&#xFF0C;someMethod( )&#x524D;&#x9762;&#x7684;public&#x548C;abstract&#x5173;&#x952E;&#x5B57;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x5728;&#x63A5;&#x53E3;&#x5185;&#x7684;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#xFF08;&#x9664;&#x4E86;&#x9ED8;&#x8BA4;&#x7C7B;&#x578B;&#x65B9;&#x6CD5;&#xFF09;&#xFF0C;&#x90FD;&#x662F;&#x201C;&#x5171;&#x6709;&#x7684;&#x201D;&#x548C;&#x201C;&#x62BD;&#x8C61;&#x7684;&#x201D;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x4E24;&#x4E2A;&#x5173;&#x952E;&#x5B57;&#x5373;&#x4F7F;&#x7701;&#x7565;&#x4E86;&#xFF0C;&#x201C;&#x667A;&#x80FD;&#x201D;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#x4E5F;&#x4F1A;&#x66FF;&#x6211;&#x4EEC;&#x628A;&#x8FD9;&#x4E24;&#x4E2A;&#x5173;&#x952E;&#x5B57;&#x52A0;&#x4E0A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x7B2C;09~15&#x884C;&#x5B9A;&#x4E49;&#x4E86;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;faceB&#xFF0C;&#x5176;&#x4E2D;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x548C;&#x63A5;&#x53E3;faceA&#x540C;&#x540D;&#x7684;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;DefaultMethod( )&#xFF0C;&#x5176;&#x5B9E;&#x8FD9;&#x4E24;&#x4E2A;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#x90E8;&#x5206;&#x5E76;&#x4E0D;&#x76F8;&#x540C;&#x3002;</p>
<p>&#x7B2C;16~21&#x884C;&#x5B9A;&#x4E49;&#x4E86;&#x5B50;&#x7C7B;DefaultMethodClass&#xFF0C;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;faceA&#x548C;faceB&#xFF0C;&#x5E76;&#x5BF9;&#x63A5;&#x53E3;faceA &#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;someMethod( )&#x7ED9;&#x4E88;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x7B2C;26&#x884C;&#xFF0C;&#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;DefaultMethodClass&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x5982;&#x679C;&#x7F16;&#x8BD1;&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x4E3A;&#x5728;&#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;DefaultMethodClass&#x7684;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4E0D;&#x77E5;&#x9053;&#x5E94;&#x8BE5;&#x5728;&#x4E24;&#x4E2A;&#x540C;&#x540D;&#x7684;default&#x65B9;&#x6CD5;&#x2014;&#x2014;DefaultMethod&#x4E2D;&#x9009;&#x62E9;&#x54EA;&#x4E00;&#x4E2A;&#xFF08;Duplicate default methods named DefaultMethod&#xFF09;&#xFF0C;&#x56E0;&#x6B64;&#x4EA7;&#x751F;&#x4E86;&#x4E8C;&#x4E49;&#x6027;&#x3002;</p>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x4E00;&#x4E2A;&#x7C7B;&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#x65F6;&#xFF0C;&#x82E5;&#x63A5;&#x53E3;&#x4E2D;&#x6709;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF0C;&#x4E0D;&#x80FD;&#x51FA;&#x73B0;&#x540C;&#x540D;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x4E8B;&#x5B9E;&#x4E0A;&#xFF0C;Java&#x4E4B;&#x6240;&#x4EE5;&#x7981;&#x6B62;&#x591A;&#x7EE7;&#x627F;&#xFF0C;&#x5C31;&#x662F;&#x60F3;&#x907F;&#x514D;&#x7C7B;&#x4F3C;&#x7684;&#x4E8C;&#x4E49;&#x6027;&#x3002;</p>
<p>&#x4F46;&#x5728;&#x63A5;&#x53E3;&#x4E2D;&#x5141;&#x8BB8;&#x5B9E;&#x73B0;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF0C;&#x4F3C;&#x4E4E;&#x53C8;&#x91CD;&#x65B0;&#x5F00;&#x542F;&#x4E86;&#x201C;&#x4E8C;&#x4E49;&#x6027;&#x201D;&#x7684;&#x707E;&#x96BE;&#x4E4B;&#x95E8;&#x3002;</p>
<p>&#x5728;&#x201C;&#x53D8;&#x76F8;&#x201D;&#x5B9E;&#x73B0;&#x7684;&#x591A;&#x7EE7;&#x627F;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x8BF4;&#x5728;&#x4E00;&#x4E2A;&#x5B50;&#x7C7B;&#x4E2D;&#x65E2;&#x8981;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF0C;&#x53C8;&#x8981;&#x7EE7;&#x627F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5219;&#x5E94;&#x8BE5;&#x91C7;&#x7528;&#x5148;&#x7EE7;&#x627F;&#x540E;&#x5B9E;&#x73B0;&#x7684;&#x987A;&#x5E8F;&#x5B8C;&#x6210;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-7 &#x5B50;&#x7C7B;&#x540C;&#x65F6;&#x7EE7;&#x627F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5E76;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF08;ExtendsInterface.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">interface</span> faceA 
&#x3000;<span class="token punctuation">{</span>&#x3000; <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</span>
&#x3000;&#x3000; <span class="token class-name">String</span> INFO <span class="token operator">=</span> <span class="token string">&quot;Hello World.&quot;</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>  <span class="token comment">// &#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">interface</span> faceB 
&#x3000;<span class="token punctuation">{</span>&#x3000;<span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">get</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">abstract</span> <span class="token keyword">class</span> abstractC 
&#x3000;<span class="token punctuation">{</span>  <span class="token comment">// &#x62BD;&#x8C61;&#x7C7B;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">fun</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>&#x3000; <span class="token comment">// &#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> subClass <span class="token keyword">extends</span> abstractC <span class="token keyword">implements</span> faceA<span class="token punctuation">,</span>faceB 

&#x3000;<span class="token punctuation">{</span>  <span class="token comment">// &#x5148;&#x7EE7;&#x627F;&#x540E;&#x5B9E;&#x73B0;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>INFO<span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">get</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x4F60;&#x597D;&#xFF01;&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fun</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x4F60;&#x597D;&#xFF01;JAVA&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ExtendsInterface</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span> args<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  subClass subObj <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token function">subClass</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token comment">// &#x5B9E;&#x4F8B;&#x5316;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;</span>
&#x3000;&#x3000;&#x3000;  faceA fa <span class="token operator">=</span> subObj <span class="token punctuation">;</span>&#x3000;<span class="token comment">// &#x4E3A;&#x7236;&#x63A5;&#x53E3;&#x5B9E;&#x4F8B;&#x5316;</span>
&#x3000;&#x3000;&#x3000;  faceB fb <span class="token operator">=</span> subObj <span class="token punctuation">;</span>&#x3000;<span class="token comment">// &#x4E3A;&#x7236;&#x63A5;&#x53E3;&#x5B9E;&#x4F8B;&#x5316;</span>
&#x3000;&#x3000;&#x3000;  abstractC ac <span class="token operator">=</span> subObj <span class="token punctuation">;</span>&#x3000;<span class="token comment">// &#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#x5B9E;&#x4F8B;&#x5316;</span>
&#x3000;
&#x3000;&#x3000;&#x3000;  fa<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  fb<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  ac<span class="token punctuation">.</span><span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;01~05&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;faceA&#xFF0C;&#x7136;&#x540E;&#x5728;&#x91CC;&#x9762;&#x58F0;&#x660E;&#x4E86;1&#x4E2A;&#x5E38;&#x91CF;INFO&#x5E76;&#x8D4B;&#x521D;&#x503C;&quot;Hello World.&quot;&#xFF0C;&#x540C;&#x65F6;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;print( )&#x3002;</p>
<p>&#x7B2C;06~09&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;faceB&#xFF0C;&#x5728;&#x5176;&#x5185;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;get()&#x3002;</p>
<p>&#x7B2C;10~13&#x884C;&#x58F0;&#x660E;&#x62BD;&#x8C61;&#x7C7B;abstractC&#xFF0C;&#x5728;&#x5176;&#x5185;&#x5B9A;&#x4E49;&#x4E86;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;fun()&#x3002;</p>
<p>&#x7B2C;14~28&#x884C;&#x58F0;&#x660E;&#x5B50;&#x7C7B;subClass&#xFF0C;&#x5B83;&#x5148;&#x7EE7;&#x627F;&#xFF08;extends&#xFF09;&#x62BD;&#x8C61;&#x7C7B;B&#xFF0C;&#x968F;&#x540E;&#x5B9E;&#x73B0;&#xFF08;implements&#xFF09;&#x63A5;&#x53E3;faceA&#x548C;faceB&#x3002;</p>
<p>&#x7B2C;33&#x884C;&#x5B9E;&#x4F8B;&#x5316;&#x4E86;&#x5B50;&#x7C7B;subClass&#x7684;&#x5BF9;&#x8C61;subObj&#x3002;</p>
<p>&#x7B2C;34~35&#x884C;&#x5B9E;&#x73B0;&#x7236;&#x63A5;&#x53E3;&#x5B9E;&#x4F8B;&#x5316;&#x3002;</p>
<p>&#x7B2C;36&#x884C;&#x5B9E;&#x73B0;&#x62BD;&#x8C61;&#x7C7B;&#x5B9E;&#x4F8B;&#x5316;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x975E;&#x8981;&#x201C;&#x8C03;&#x76AE;&#x5730;&#x201D;&#x628A;&#x7B2C;14&#x884C;&#x4EE3;&#x7801;&#xFF0C;&#x4ECE;&#x539F;&#x6765;&#x7684;&#x201C;&#x7EE7;&#x627F;&#x5728;&#x5148;&#xFF0C;&#x5B9E;&#x73B0;&#x5728;&#x540E;&#x201D;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>class subClass extends abstractC implements faceA,faceB&#x6539;&#x6210;&#x201C;&#x5B9E;&#x73B0;&#x5728;&#x5148;&#xFF0C;&#x7EE7;&#x627F;&#x5728;&#x540E;&#x201D;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>class subClass implements faceA,faceB extends abstractC&#x7F16;&#x8BD1;&#x5668;&#x662F;&#x4E0D;&#x4F1A;&#x7B54;&#x5E94;&#x7684;&#xFF0C;&#x5B83;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>9.2.3 &#x63A5;&#x53E3;&#x7684;&#x4F5C;&#x7528;&#x2014;&#x2014;Java&#x7684;&#x56DE;&#x8C03;&#x673A;&#x5236;&#x56DE;&#x8C03;&#xFF08;callback&#xFF09;&#x662F;Java&#x4E2D;&#x5F88;&#x91CD;&#x8981;&#x7684;&#x4E00;&#x4E2A;&#x6982;&#x5FF5;&#xFF0C;&#x5728;&#x540E;&#x9762;&#x7AE0;&#x8282;&#x8BB2;&#x89E3;&#x7684;Spring&#x3001;Hibernate&#x7B49;&#x8BA1;&#x7B97;&#x6846;&#x67B6;&#x4E2D;&#xFF0C;&#x90FD;&#x5927;&#x91CF;&#x4F7F;&#x7528;&#x4E86;&#x56DE;&#x8C03;&#x6280;&#x672F;&#xFF0C;&#x6240;&#x4EE5;&#x6709;&#x5FC5;&#x8981;&#x4E86;&#x89E3;&#x4E00;&#x4E0B;&#x8FD9;&#x4E2A;&#x673A;&#x5236;&#x3002;</p>
<p>&#x5728;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x6709;&#x4E2A;&#x8F83;&#x65B0;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;&#x53EB;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#xFF08;Inversion of Control&#xFF0C;IoC&#xFF09;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x91CD;&#x8981;&#x7684;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7F16;&#x7A0B;&#x7684;&#x6CD5;&#x5219;&#xFF0C;&#x7528;&#x6765;&#x524A;&#x51CF;&#x8BA1;&#x7B97;&#x673A;&#x7A0B;&#x5E8F;&#x7684;&#x8026;&#x5408;&#x95EE;&#x9898;&#xFF0C;&#x4E5F;&#x662F;&#x8F7B;&#x91CF;&#x7EA7;&#x7684;Spring&#x6846;&#x67B6;&#x7684;&#x6838;&#x5FC3;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x6982;&#x5FF5;&#x76F8;&#x5BF9;&#x8F83;&#x65B0;&#xFF0C;&#x5728;Erich Gamma&#x7B49;&#x56DB;&#x4EBA;&#x7EC4;&#x5408;&#x8457;&#x7684;&#x300A;Design Patterns&#x300B;&#xFF08;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#xFF09;&#x4E2D;&#xFF0C;&#x5E76;&#x6CA1;&#x6709;&#x4F53;&#x73B0;&#x8FD9;&#x4E00;&#x6A21;&#x5F0F;&#x3002;</p>
<p>&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#x7684;&#x672C;&#x8D28;&#xFF0C;&#x5C31;&#x662F;Java&#x4E2D;&#x7684;&#x56DE;&#x8C03;&#x673A;&#x5236;&#x3002;</p>
<p>&#x201C;&#x56DE;&#x8C03;&#x201D;&#xFF0C;&#x5176;&#x82F1;&#x6587;&#x201C;call back&#x201D;&#x7684;&#x539F;&#x610F;&#x662F;&#x201C;&#x56DE;&#x7535;&#x8BDD;&#x201D;&#xFF0C;&#x8FD9;&#x6700;&#x65E9;&#x6E90;&#x4E8E;&#x201C;&#x597D;&#x83B1;&#x575E;&#x539F;&#x5219;&#xFF08;Hollywood principle&#xFF09;&#x201D;&#xFF1A;&#x201C;Don&apos;t call me, we will callyou&#xFF08;&#x4E0D;&#x8981;&#x7ED9;&#x6211;&#x6253;&#x7535;&#x8BDD;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x6253;&#x7ED9;&#x4F60;&#xFF09;&#x201D;&#x3002;</p>
<p>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5982;&#x679C;&#x597D;&#x83B1;&#x575E;&#x660E;&#x661F;&#x60F3;&#x6F14;&#x8282;&#x76EE;&#xFF0C;&#x4E0D;&#x7528;&#x81EA;&#x5DF1;&#x53BB;&#x627E;&#x597D;&#x83B1;&#x575E;&#x516C;&#x53F8;&#xFF0C;&#x800C;&#x662F;&#x7531;&#x597D;&#x83B1;&#x575E;&#x516C;&#x53F8;&#x4E3B;&#x52A8;&#x53BB;&#x627E;&#x4ED6;&#x4EEC;&#xFF08;&#x5F53;&#x7136;&#xFF0C;&#x4E4B;&#x524D;&#x8FD9;&#x4E9B;&#x660E;&#x661F;&#x5FC5;&#x987B;&#x8981;&#x5728;&#x597D;&#x83B1;&#x575E;&#x767B;&#x8BB0;&#x8FC7;&#xFF09;&#x3002;</p>
<p>&#x8A00;&#x5916;&#x4E4B;&#x610F;&#xFF0C;&#x867D;&#x7136;&#x6211;&#x4EEC;&#x4E4B;&#x95F4;&#x6709;&#x901A;&#x7535;&#x8BDD;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x4F1A;&#x5728;&#x9700;&#x8981;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x518D;&#x786E;&#x5B9A;&#x4E0B;&#x6765;&#x901A;&#x7535;&#x8BDD;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5728;&#x67D0;&#x4E9B;&#x9762;&#x5411;&#x8FC7;&#x7A0B;&#xFF08;&#x4E8B;&#x4EF6;&#x9A71;&#x52A8;&#xFF09;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#xFF08;&#x5982;C&#x8BED;&#x8A00;&#xFF09;&#x4E2D;&#xFF0C;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4F20;&#x9012;&#x51FD;&#x6570;&#x6307;&#x9488;&#xFF08;function pointer&#xFF09;&#x76F4;&#x63A5;&#x5B9E;&#x73B0;&#x56DE;&#x8C03;&#x673A;&#x5236;&#xFF0C;&#x56DE;&#x8C03;&#x7684;&#x5BF9;&#x8C61;&#x53EF;&#x80FD;&#x662F;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#x5757;&#xFF08;&#x65B9;&#x6CD5;&#x5757;&#xFF09;&#x3002;</p>
<p>&#x4F46;Java&#x4F5C;&#x4E3A;&#x4E00;&#x95E8;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#xFF0C;&#x5E76;&#x4E0D;&#x652F;&#x6301;&#x65B9;&#x6CD5;&#x6307;&#x9488;&#xFF08;method pointer&#xFF0C;&#x5728;Java&#x4E2D;&#xFF0C;&#x65B9;&#x6CD5;&#x7684;&#x5730;&#x4F4D;&#x7B49;&#x540C;&#x4E8E;C&#x4E2D;&#x7684;&#x51FD;&#x6570;&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x60F3;&#x5B9E;&#x73B0;&#x56DE;&#x8C03;&#x673A;&#x5236;&#xFF0C;&#x5FC5;&#x987B;&#x901A;&#x8FC7;&#x201C;&#x5BF9;&#x8C61;&#xFF08;object&#xFF09;&#x201D;&#x6765;&#x5B8C;&#x6210;&#xFF0C;&#x8FD9;&#x4F3C;&#x4E4E;&#x59A8;&#x788D;&#x4E86;&#x56DE;&#x8C03;&#x673A;&#x5236;&#x7684;&#x5B8C;&#x6210;&#x3002;</p>
<p>Java&#x201C;&#x5173;&#x4E0A;&#x4E86;&#x4E00;&#x6247;&#x95E8;&#xFF0C;&#x5FC5;&#x7136;&#x4F1A;&#x4E3A;&#x4F60;&#x5F00;&#x542F;&#x53E6;&#x4E00;&#x6247;&#x7A97;&#x201D;&#xFF0C;&#x800C;&#x8FD9;&#x6247;&#x7A97;&#x5C31;&#x662F;&#x201C;&#x63A5;&#x53E3;&#x201D;&#x3002;</p>
<p>&#x5728;Java&#x4E2D;&#xFF0C;&#x56DE;&#x8C03;&#x6D41;&#x7A0B;&#x901A;&#x5E38;&#x8981;&#x4ECE;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x5F00;&#x59CB;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x4E3E;&#x4F8B;&#x8BF4;&#x660E;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-8 Java&#x56DE;&#x8C03;&#x673A;&#x5236;&#x7684;&#x6F14;&#x793A;&#xFF08;Caller.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">interface</span> <span class="token class-name">CallBack</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">void</span> <span class="token function">methodToCallBack</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">CallBackImpl</span> <span class="token keyword">implements</span> <span class="token class-name">CallBack</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">methodToCallBack</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;I&apos;&quot;</span>ve been called back&quot;<span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Caller</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">register</span><span class="token punctuation">(</span><span class="token class-name">CallBack</span> callback<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  callback<span class="token punctuation">.</span><span class="token function">methodToCallBack</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Caller</span> caller <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Caller</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">CallBack</span> callBack <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CallBackImpl</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  caller<span class="token punctuation">.</span><span class="token function">register</span><span class="token punctuation">(</span>callBack<span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;01~04&#x884C;&#xFF0C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;CallBack&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x4E2D;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;methodToCallBack( )&#x3002;</p>
<p>&#x7B2C;05~11&#x884C;&#xFF0C;&#x7528;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;CallBackImpl&#x7684;&#x7C7B;&#xFF0C;&#x5B9E;&#x73B0;&#x4E86;&#x63A5;&#x53E3;CallBack&#x3002;</p>
<p>&#x7B2C;12~24&#x884C;&#xFF0C;&#x8BBE;&#x8BA1;&#x4E86;&#x4E00;&#x4E2A;&#x4E3B;&#x8C03;&#x7C7B;Caller&#xFF0C;&#x5176;&#x4E2D;&#x7B2C;14~17&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x6CE8;&#x518C;&#x65B9;&#x6CD5;register()&#xFF0C;&#x7279;&#x522B;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x662F;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;CallBack&#x7684;&#x5F15;&#x7528;&#x3002;</p>
<p>&#x7B2C;20&#x884C;&#xFF0C;&#x65B0;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;Caller&#x5BF9;&#x8C61;&#xFF0C;&#x7B2C;21&#x884C;&#x65B0;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;CallBackImpl&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5B83;&#x662F;&#x63A5;&#x53E3;CallBack&#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x8005;&#x3002;</p>
<p>&#x7B2C;22&#x884C;&#xFF0C;&#x8C03;&#x7528;&#x6CE8;&#x518C;&#x65B9;&#x6CD5;register()&#xFF0C;&#x5B9E;&#x53C2;&#x5C31;&#x662F;CallBackImpl&#x7684;&#x5BF9;&#x8C61;callBack&#xFF0C;&#x56E0;&#x4E3A;CallBackImpl&#x5B9E;&#x73B0;&#xFF08;&#x67D0;&#x79CD;&#x7A0B;&#x5EA6;&#x4E0A;&#x53EF;&#x4EE5;&#x8BF4;&#x662F;&#x7EE7;&#x627F;&#xFF09;&#x4E86;&#x62BD;&#x8C61;&#x63A5;&#x53E3;&#xFF0C;&#x6240;&#x4EE5;&#x5728;register()&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;callBack&#x53EF;&#x4EE5;&#x8C03;&#x7528;methodToCallBack()&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x6216;&#x8BB8;&#xFF0C;&#x8BFB;&#x8005;&#x4F1A;&#x56F0;&#x60D1;&#xFF0C;&#x4E3A;&#x4EC0;&#x4E48;&#x4E0D;&#x5728;&#x7B2C;21&#x884C;&#x4E4B;&#x540E;&#x8FD9;&#x4E48;&#x505A;&#x3002;</p>
<p>callback.methodToCallBack()&#x8FD9;&#x6837;&#x5C82;&#x4E0D;&#x662F;&#x66F4;&#x52A0;&#x7B80;&#x4FBF;&#xFF1F;&#x7684;&#x786E;&#x5982;&#x6B64;&#x3002;</p>
<p>&#x4F46;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x4E0D;&#x5728;&#x4E8E;&#x5982;&#x4F55;&#x7528;&#x6700;&#x77ED;&#x7684;&#x4EE3;&#x7801;&#x5B9E;&#x73B0;&#x5177;&#x4F53;&#x529F;&#x80FD;&#xFF0C;&#x800C;&#x662F;&#x4E3A;&#x4E86;&#x7ED9;&#x6211;&#x4EEC;&#x5C55;&#x793A;&#x4E00;&#x4E0B;&#xFF0C;&#x5982;&#x4F55;&#x5728;Java&#x73AF;&#x5883;&#x4E0B;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x56DE;&#x8C03;&#x673A;&#x5236;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;&#x56DE;&#x8C03;&#x673A;&#x5236;&#x7684;&#x771F;&#x6B63;&#x610F;&#x56FE;&#xFF0C;&#x5176;&#x5B9E;&#x662F;&#x4E3A;&#x4E86;&#x5B9E;&#x73B0;&#x201C;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#xFF08;Inversion of Control&#xFF09;&#x201D;&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#xFF0C;&#x5BF9;&#x8C61;&#x5728;&#x88AB;&#x521B;&#x5EFA;&#x7684;&#x65F6;&#x5019;&#xFF08;&#x5982;&#x7B2C;21&#x884C;&#xFF09;&#xFF0C;&#x7531;&#x4E00;&#x4E2A;&#x80FD;&#x591F;&#x8C03;&#x63A7;&#x7CFB;&#x7EDF;&#x5185;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x5916;&#x754C;&#x5B9E;&#x4F53;&#xFF08;&#x5982;&#x7B2C;20&#x884C;&#x7684;caller&#xFF09;&#xFF0C;&#x5C06;&#x5176;&#x6240;&#x4F9D;&#x8D56;&#x7684;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#x4F20;&#x9012;&#x7ED9;&#x529F;&#x80FD;&#x65B9;&#x6CD5;&#x5757;&#xFF08;&#x5982;&#x7B2C;22&#x884C;&#x7684;callBack&#xFF0C;&#x88AB;&#x9001;&#x5165;&#x5230;register()&#x4E2D;&#xFF09;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;&#x540C;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x53EF;&#x4EE5;&#x6709;&#x4E0D;&#x540C;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x4ECE;&#x800C;&#x4F7F;&#x5F97;&#x8FD9;&#x4E9B;&#x4E0D;&#x540C;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x4F17;&#x591A;&#x4E0D;&#x540C;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x8FD9;&#x4E9B;&#x5BF9;&#x8C61;&#x4F1A;&#x88AB;&#x6309;&#x9700;&#x201C;&#x6CE8;&#x5165;&#x201D;&#x529F;&#x80FD;&#x65B9;&#x6CD5;&#x5757;register()&#x3002;</p>
<p>&#x5728;&#x88AB;&#x8C03;&#x7528;&#x524D;&#xFF0C;&#x8FD9;&#x4E9B;&#x5BF9;&#x8C61;&#x6C38;&#x8FDC;&#x5904;&#x4E8E;&#x7B49;&#x5F85;&#x8C03;&#x7528;&#x72B6;&#x6001;&#xFF0C;&#x76F4;&#x5230;&#x6709;&#x4E00;&#x5929;&#x88AB;&#x56DE;&#x8C03;&#xFF08;callback&#xFF09;&#x3002;</p>
<p>&#x7531;&#x4E0A;&#x5206;&#x6790;&#x53EF;&#x77E5;&#xFF0C;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x964D;&#x4F4E;&#x8BA1;&#x7B97;&#x673A;&#x4EE3;&#x7801;&#x4E4B;&#x95F4;&#x7684;&#x8026;&#x5408;&#x5EA6;&#x3002;</p>
<p>&#x5728;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#x7684;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x63D0;&#x51FA;&#x4E4B;&#x540E;&#xFF0C;&#x5F15;&#x8D77;&#x4E86;&#x5F88;&#x5927;&#x7684;&#x5173;&#x6CE8;&#x548C;&#x4E89;&#x8BAE;&#x3002;</p>
<p>&#x4E8E;&#x662F;&#xFF0C;&#x8D44;&#x6DF1;&#x7A0B;&#x5E8F;&#x5458;&#x9A6C;&#x4E01; &#x25CF; &#x798F;&#x52D2;&#xFF08;Martin Fowler&#xFF09;&#x53D1;&#x8868;&#x4E86;&#x4E00;&#x7BC7;&#x7ECF;&#x5178;&#x6587;&#x7AE0;&#x300A;Inversionof Control Containers and the Dependency Injection pattern&#x300B;&#xFF08;&#x63A7;&#x5236;&#x5BB9;&#x5668;&#x7684;&#x53CD;&#x8F6C;&#x548C;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#x6A21;&#x5F0F;&#xFF09;&#xFF0C;&#x7EC8;&#x4E8E;&#x7B97;&#x662F;&#x5E73;&#x606F;&#x4E86;&#x4E89;&#x8BBA;&#x3002;</p>
<p>&#x4E8E;&#x662F;&#xFF0C;&#x201C;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#x201D;&#x53C8;&#x83B7;&#x5F97;&#x4E86;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x540D;&#x5B57;&#xFF1A;&#x201C;&#x4F9D;&#x8D56;&#x6CE8;&#x5165; &#xFF08;Dependency Injection&#xFF09;&#x201D;&#x3002;</p>
<p>&#x201C;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#x201D;&#x7684;&#x786E;&#x66F4;&#x52A0;&#x51C6;&#x786E;&#x5730;&#x63CF;&#x8FF0;&#x4E86;&#x8FD9;&#x79CD;&#x8BBE;&#x8BA1;&#x7406;&#x5FF5;&#x3002;</p>
<p>&#x6240;&#x8C13;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#xFF0C;&#x5C31;&#x662F;&#x6307;&#x7EC4;&#x4EF6;&#x4E4B;&#x95F4;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x7531;&#x5BB9;&#x5668;&#x5728;&#x8FD0;&#x884C;&#x671F;&#x51B3;&#x5B9A;&#xFF0C;&#x5728;&#x6CE8;&#x5165;&#x4E4B;&#x524D;&#xFF0C;&#x5BF9;&#x8C61;&#x4E4B;&#x95F4;&#x7684;&#x8026;&#x5408;&#x5173;&#x7CFB;&#x662F;&#x677E;&#x6563;&#x7684;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x518D;&#x5217;&#x4E3E;&#x4E00;&#x4E2A;&#x66F4;&#x52A0;&#x5B9E;&#x7528;&#x7684;&#x6848;&#x4F8B;&#xFF0C;&#x6765;&#x8BF4;&#x660E;Java&#x4E2D;&#x7684;&#x56DE;&#x8C03;&#x673A;&#x5236;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-9 &#x5229;&#x7528;&#x63A5;&#x53E3;&#x5B9E;&#x73B0;Java&#x4E2D;&#x7684;&#x56DE;&#x8C03;&#x673A;&#x5236;&#xFF08;callBackDemo.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">import</span> <span class="token namespace">java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span></span><span class="token class-name">Rectangle</span><span class="token punctuation">;</span>
&#x3000;<span class="token keyword">interface</span> <span class="token class-name">Measurer</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">double</span> <span class="token function">measure</span><span class="token punctuation">(</span><span class="token class-name">Object</span> anObject<span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">AreaMeasurer</span> <span class="token keyword">implements</span> <span class="token class-name">Measurer</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">double</span> <span class="token function">measure</span><span class="token punctuation">(</span><span class="token class-name">Object</span> anObject<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Rectangle</span> aRectangle <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Rectangle</span><span class="token punctuation">)</span> anObject<span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">double</span> area <span class="token operator">=</span> aRectangle<span class="token punctuation">.</span><span class="token function">getWidth</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">*</span> aRectangle<span class="token punctuation">.</span><span class="token function">getHeight</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> area<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span> 
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">Car</span> 
&#x3000;<span class="token punctuation">{</span>  
&#x3000;&#x3000; <span class="token keyword">private</span> <span class="token keyword">double</span> price<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">private</span> <span class="token keyword">double</span> taxRate<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token class-name">Car</span><span class="token punctuation">(</span><span class="token keyword">double</span> price<span class="token punctuation">,</span> <span class="token keyword">double</span> taxRate<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">this</span><span class="token punctuation">.</span>price <span class="token operator">=</span> price<span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">this</span><span class="token punctuation">.</span>taxRate <span class="token operator">=</span> taxRate<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">double</span> <span class="token function">getPrice</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> price<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">double</span> <span class="token function">getRate</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> taxRate<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">CarMeasurer</span> <span class="token keyword">implements</span> <span class="token class-name">Measurer</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">double</span> <span class="token function">measure</span><span class="token punctuation">(</span><span class="token class-name">Object</span> anObject<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Car</span> aCar <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">Car</span><span class="token punctuation">)</span> anObject<span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">double</span> totalPrice <span class="token operator">=</span> aCar<span class="token punctuation">.</span><span class="token function">getPrice</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">1</span> <span class="token operator">+</span> aCar<span class="token punctuation">.</span><span class="token function">getRate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> totalPrice<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span> 
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">class</span> <span class="token class-name">Data</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">double</span> <span class="token function">average</span><span class="token punctuation">(</span><span class="token class-name">Object</span><span class="token punctuation">[</span><span class="token punctuation">]</span> objects<span class="token punctuation">,</span> <span class="token class-name">Measurer</span> meas<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">double</span> sum <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">Object</span> obj <span class="token operator">:</span> objects<span class="token punctuation">)</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;sum <span class="token operator">=</span> sum <span class="token operator">+</span> meas<span class="token punctuation">.</span><span class="token function">measure</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">}</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">if</span> <span class="token punctuation">(</span>objects<span class="token punctuation">.</span>length <span class="token operator">&amp;</span>gt<span class="token punctuation">;</span> <span class="token number">0</span><span class="token punctuation">)</span> 
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">return</span> sum <span class="token operator">/</span> objects<span class="token punctuation">.</span>length<span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> 
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">}</span> 
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> callBackDemo
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Measurer</span> areaMeas <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AreaMeasurer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Rectangle</span><span class="token punctuation">[</span><span class="token punctuation">]</span> rects <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Rectangle</span><span class="token punctuation">[</span><span class="token punctuation">]</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">new</span> <span class="token class-name">Rectangle</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> 
<span class="token punctuation">,</span> 
<span class="token punctuation">,</span> 
<span class="token punctuation">)</span><span class="token punctuation">,</span> 
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">new</span> <span class="token class-name">Rectangle</span><span class="token punctuation">(</span>
<span class="token punctuation">,</span> 
<span class="token punctuation">,</span> 
<span class="token punctuation">,</span> 
<span class="token punctuation">)</span><span class="token punctuation">,</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">new</span> <span class="token class-name">Rectangle</span><span class="token punctuation">(</span>
<span class="token punctuation">,</span> 
<span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> 
<span class="token punctuation">)</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">}</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token keyword">double</span> averageArea <span class="token operator">=</span> <span class="token class-name">Data</span><span class="token punctuation">.</span><span class="token function">average</span><span class="token punctuation">(</span>rects<span class="token punctuation">,</span> areaMeas<span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x5E73;&#x5747;&#x9762;&#x79EF;&#x4E3A;: &quot;</span> <span class="token operator">+</span> averageArea<span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; 
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Measurer</span> carMeas <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CarMeasurer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Car</span><span class="token punctuation">[</span><span class="token punctuation">]</span> cars <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Car</span><span class="token punctuation">[</span><span class="token punctuation">]</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">new</span> <span class="token class-name">Car</span><span class="token punctuation">(</span>

<span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0.</span>
<span class="token punctuation">)</span><span class="token punctuation">,</span> 
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">new</span> <span class="token class-name">Car</span><span class="token punctuation">(</span>

<span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0.</span>
<span class="token punctuation">)</span><span class="token punctuation">,</span> 
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">new</span> <span class="token class-name">Car</span><span class="token punctuation">(</span>

<span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0.</span>
<span class="token punctuation">)</span><span class="token punctuation">,</span> 
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">}</span><span class="token punctuation">;</span> 
&#x3000;&#x3000;&#x3000;  <span class="token keyword">double</span> averagePrice <span class="token operator">=</span> <span class="token class-name">Data</span><span class="token punctuation">.</span><span class="token function">average</span><span class="token punctuation">(</span>cars<span class="token punctuation">,</span> carMeas<span class="token punctuation">)</span><span class="token punctuation">;</span> 

&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x5E73;&#x5747;&#x4EF7;&#x683C;&#x4E3A;: &quot;</span><span class="token operator">+</span> averagePrice<span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000;  
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x5728;&#x7B2C;02~05&#x884C;&#xFF0C;&#x58F0;&#x660E;&#x4E86;&#x5982;&#x4E0B;&#x4E00;&#x4E2A;&#x6D4B;&#x91CF;&#x5668;&#x7684;&#x63A5;&#x53E3;Measurer&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x91CC;&#xFF0C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;measure( )&#x65B9;&#x6CD5;&#xFF0C;&#x5F88;&#x660E;&#x663E;&#xFF0C;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x53EA;&#x6709;&#x65B9;&#x6CD5;&#x58F0;&#x660E;&#xFF0C;&#x800C;&#x6CA1;&#x6709;&#x5B9E;&#x73B0;&#x65B9;&#x6CD5;&#x4F53;&#x3002;</p>
<p>&#x6B64;&#x5916;&#xFF0C;&#x8FD8;&#x5E94;&#x8BE5;&#x6CE8;&#x610F;&#x5230;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;measure&#x65B9;&#x6CD5;&#x5185;&#xFF0C;&#x6D4B;&#x91CF;&#x7684;&#x662F;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#xFF08;Object&#xFF09;&#xFF0C;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#xFF0C;&#x5E76;&#x4E0D;&#x660E;&#x786E;&#x3002;</p>
<p>&#x4E0D;&#x660E;&#x786E;&#x7684;&#x7528;&#x610F;&#x5728;&#x4E8E;&#xFF0C;&#x5148;&#x4E0D;&#x7ED1;&#x5B9A;&#x4EFB;&#x4F55;&#x7279;&#x5B9A;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x7B2C;06~14&#x884C;&#xFF0C;&#x901A;&#x8FC7;AreaMeasurer&#x7C7B;&#x6765;&#x5B9E;&#x73B0;&#xFF08;implement&#xFF09;Measurer&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x8FD9;&#x65F6;&#xFF0C;&#x628A;&#x62BD;&#x8C61;&#x7684;&#x65B9;&#x6CD5;measure( )&#x5177;&#x4F53;&#x5316;&#xFF0C;&#x628A;&#x62BD;&#x8C61;&#x7684;&#x5BF9;&#x8C61;&#x660E;&#x786E;&#x5316;&#xFF08;Rectangle aRectangle = (Rectangle) anObject&#xFF09;&#xFF0C;&#x624D;&#x80FD;&#x4F7F;&#x7528;&#x3002;</p>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x5728;Java&#x7684;&#x7EE7;&#x627F;&#x4F53;&#x7CFB;&#x4E2D;&#xFF0C;&#x7531;&#x4E8E;Object&#x5BF9;&#x8C61;&#x662F;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x201C;&#x9F3B;&#x7956;&#x201D;&#xFF0C;&#x56E0;&#x6B64;&#xFF0C;Object&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x201C;&#x5316;&#x8EAB;&#x201D;&#x4E3A;&#x4EFB;&#x4F55;&#x7C7B;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#x3002;</p>
<p>&#x7B2C;42~58&#x884C;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;Data&#x7C7B;&#xFF0C;&#x8FD9;&#x4E2A;&#x7C7B;&#x8D1F;&#x8D23;&#x6C42;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x5747;&#x503C;&#x3002;</p>
<p>&#x4F46;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;average( )&#x6240;&#x4EE3;&#x8868;&#x7684;&#x7B97;&#x6CD5;&#xFF0C;&#x548C;&#x5176;&#x64CD;&#x4F5C;&#x7684;&#x5BF9;&#x8C61;&#x662F;&#x677E;&#x8026;&#x5408;&#x7684;&#x3002;</p>
<p>&#x56E0;&#x4E3A;&#x8FD9;&#x4E2A;average( )&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x62BD;&#x8C61;&#x7684;&#x5BF9;&#x8C61;&#xFF08;Object&#xFF09;&#x7C7B;&#x578B;&#x6570;&#x7EC4;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x62BD;&#x8C61;&#x7684;&#x6D4B;&#x91CF;&#x63A5;&#x53E3;Measurer&#x7C7B;&#x578B;&#x3002;</p>
<p>&#x5176;&#x7279;&#x522B;&#x4E4B;&#x5904;&#x5728;&#x4E8E;&#xFF0C;&#x628A;&#x6C42;&#x5747;&#x503C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x548C;&#x6C42;&#x5747;&#x503C;&#x7684;&#x5BF9;&#x8C61;&#x6682;&#x65F6;&#x5206;&#x5272;&#x5F00;&#xFF08;&#x4E5F;&#x53EF;&#x4EE5;&#x8BA4;&#x4E3A;&#x662F;&#x89E3;&#x8026;&#xFF09;&#x3002;</p>
<p>&#x968F;&#x540E;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x9047;&#x5230;&#x5BF9;&#x8C61;&#x662F;&#x77E9;&#x5F62;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5C31;&#x6C42;&#x77E9;&#x5F62;&#x9762;&#x79EF;&#x7684;&#x5747;&#x503C;&#xFF08;&#x7B2C;06~14&#x884C;&#xFF09;&#x3002;</p>
<p>&#x5982;&#x679C;&#x540E;&#x671F;&#x6211;&#x4EEC;&#x9047;&#x5230;&#x5BF9;&#x8C61;&#x662F;&#x6C7D;&#x8F66;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5C31;&#x6C42;&#x8FD9;&#x4E9B;&#x6C7D;&#x8F66;&#x552E;&#x4EF7;&#x7684;&#x5747;&#x503C;&#xFF08;&#x7B2C;15~41&#x884C;&#xFF09;&#x3002;</p>
<p>&#x663E;&#x7136;&#xFF0C;&#x8FD9;&#x79CD;&#x5EF6;&#x540E;&#x786E;&#x5B9A;&#x5BF9;&#x8C61;&#xFF0C;&#x4E4B;&#x540E;&#x201C;&#x6709;&#x7684;&#x653E;&#x77E2;&#x201D;&#x5730;&#x6C42;&#x5747;&#x503C;&#x673A;&#x5236;&#xFF0C;&#x8BA9;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x66F4;&#x5177;&#x6709;&#x4E00;&#x822C;&#x6027;&#x548C;&#x901A;&#x7528;&#x6027;&#x3002;</p>
<p>&#x867D;&#x7136;&#x6C42;&#x5747;&#x503C;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF1A;&#x5404;&#x5BF9;&#x8C61;&#x503C;&#x6C42;&#x548C;/&#x5BF9;&#x8C61;&#x4E2A;&#x6570;&#x3002;</p>
<p>&#x4F46;&#x4E0D;&#x540C;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x6709;&#x4E0D;&#x540C;&#x7684;&#x6D4B;&#x91CF;&#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x8FD9;&#x4E9B;&#x4E0D;&#x540C;&#x7684;&#x4E2A;&#x6027;&#x5316;&#x6D4B;&#x7B97;&#x65B9;&#x6CD5;&#xFF0C;&#x5219;&#x662F;&#x6765;&#x81EA;&#x4E8E;&#x5BF9;&#x63A5;&#x53E3;Measurer&#x7684;&#x4E0D;&#x540C;&#x5B9E;&#x73B0;&#x7248;&#x672C;&#xFF0C;&#x5373;&#x4E0D;&#x540C;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5B9E;&#x73B0;&#x4E0D;&#x540C;&#x7248;&#x672C;&#x7684;measure( )&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x7B2C;06~14&#x884C;&#x663E;&#x793A;&#x7684;&#x662F;&#x77E9;&#x5F62;&#x7684;&#x6D4B;&#x7B97;&#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x7B2C;33~41&#x884C;&#x5219;&#x663E;&#x793A;&#x7684;&#x6C42;&#x6C7D;&#x8F66;&#x4EF7;&#x683C;&#x7684;&#x6D4B;&#x7B97;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#x7B2C;63&#x884C;&#xFF0C;&#x660E;&#x786E;&#x6D4B;&#x91CF;&#x7684;&#x5BF9;&#x8C61;&#x4E3A;&#x9762;&#x79EF;&#x6D4B;&#x91CF;&#xFF0C;&#x7B2C;64~69&#x884C;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x5217;&#x7684;&#x77E9;&#x5F62;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x7136;&#x540E;&#x8C03;&#x7528;Data&#x7C7B;&#x7684;&#x9759;&#x6001;&#x65B9;&#x6CD5;average( )&#xFF0C;&#x5B9E;&#x53C2;rects&#xFF08;&#x77E9;&#x5F62;&#x5BF9;&#x8C61;&#x6570;&#x7EC4;&#xFF09;&#x7ED9;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x2014;&#x2014;&#x5F62;&#x53C2;objects&#x8D4B;&#x503C;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x5B9E;&#x53C2;areaMeas&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x4E00;&#x4E2A;&#x9762;&#x79EF;&#x6D4B;&#x91CF;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x88AB;&#x8D4B;&#x503C;&#x7ED9;&#x5F62;&#x53C2;meas&#x3002;</p>
<p>&#x524D;&#x9762;&#x6D89;&#x53CA;&#x51E0;&#x4E2A;&#x7C7B;&#x548C;&#x63A5;&#x53E3;&#x4E4B;&#x95F4;&#x7684;UML&#x5173;&#x7CFB;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x7C7B;&#x4F3C;&#x7684;&#xFF0C;&#x7B2C;73&#x884C;&#xFF0C;&#x660E;&#x786E;&#x6D4B;&#x91CF;&#x7684;&#x5BF9;&#x8C61;&#x4E3A;&#x8BA1;&#x7B97;&#x6C7D;&#x8F66;&#x9500;&#x552E;&#x4EF7;&#x683C;&#x5747;&#x503C;&#xFF0C;&#x7B2C;74~79&#x884C;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x5217;&#x7684;&#x77E9;&#x5F62;&#x5BF9;&#x8C61;&#xFF08;&#x5373;&#x5BF9;&#x8C61;&#x6570;&#x7EC4;&#xFF09;&#x3002;</p>
<p>&#x7136;&#x540E;&#x8C03;&#x7528;average( )&#x65B9;&#x6CD5;&#xFF0C;&#x5B9E;&#x53C2;cars&#xFF08;&#x6C7D;&#x8F66;&#x5BF9;&#x8C61;&#x6570;&#x7EC4;&#xFF09;&#xFF0C;&#x7ED9;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x2014;&#x2014;&#x5F62;&#x53C2;objects&#x8D4B;&#x503C;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x5B9E;&#x53C2;carMeas&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x4E00;&#x4E2A;&#x4EF7;&#x683C;&#x8BA1;&#x7B97;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x88AB;&#x8D4B;&#x503C;&#x7ED9;&#x5F62;&#x53C2;meas&#x3002;</p>
<p>&#x7531;&#x4E0A;&#x5206;&#x6790;&#x53EF;&#x77E5;&#xFF0C;Data&#x7C7B;&#x4E2D;&#x7684;average( )&#x65B9;&#x6CD5;&#xFF0C;&#x4ECE;Rectangle&#x3001;Car&#x7B49;&#x7C7B;&#x4E2D;&#x89E3;&#x8026;&#x51FA;&#x6765;&#x3002;</p>
<p>Rectangle&#x7C7B;&#x548C;Car&#x7C7B;&#xFF0C;&#x4E5F;&#x4E0D;&#x518D;&#x548C;&#x5176;&#x4ED6;&#x7C7B;&#x8026;&#x5408;&#xFF0C;&#x53D6;&#x800C;&#x4EE3;&#x4E4B;&#x7684;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x8BF8;&#x5982;AreaMeasure&#x3001;CarMeasure&#x7B49;&#x5C0F;&#x52A9;&#x624B;&#xFF08;&#x5373;&#x63A5;&#x53E3;Measurer&#x7684;&#x4E00;&#x4E2A;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#xFF09;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x52A9;&#x624B;&#x7C7B;&#x5B58;&#x5728;&#x7684;&#x552F;&#x4E00;&#x76EE;&#x7684;&#xFF0C;&#x5C31;&#x662F;&#x544A;&#x8BC9;average&#x65B9;&#x6CD5;&#xFF0C;&#x5982;&#x4F55;&#x6765;&#x6D4B;&#x91CF;&#x5BF9;&#x8C61;&#x7684;&#x67D0;&#x79CD;&#x5C5E;&#x6027;&#x503C;&#x7684;&#x5E73;&#x5747;&#x503C;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#x5173;&#x6CE8;&#x7684;&#x662F;&#xFF0C;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x5982;&#x4F55;&#x83B7;&#x53D6;&#x4ED6;&#x6240;&#x4F9D;&#x8D56;&#x7684;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x8FD9;&#x662F;&#x8D23;&#x4EFB;&#x7684;&#x53CD;&#x8F6C;&#x3002;</p>
<p>&#x8BF7;&#x8BFB;&#x8005;&#x53C2;&#x7167;&#x8303;&#x4F8B;9-8&#xFF0C;&#x5206;&#x6790;&#x4E00;&#x4E0B;&#xFF0C;&#x5728;&#x8303;&#x4F8B;9-9&#x4E2D;&#xFF0C;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#xFF08;&#x6216;&#x8005;&#x662F;&#x89D2;&#x8272;&#x6CE8;&#x5165;&#xFF09;&#x4F53;&#x73B0;&#x5728;&#x4EC0;&#x4E48;&#x5730;&#x65B9;&#x5462;&#xFF1F;
<a id="3"></a></p>
<h3 id="93-&#x5185;&#x90E8;&#x7C7B;">9.3 &#x5185;&#x90E8;&#x7C7B;</h3>
<p>&#x6240;&#x8C13;&#x7684;&#x5185;&#x90E8;&#x7C7B;&#xFF0C;&#x5C31;&#x662F;&#x6307;&#x5728;&#x4E00;&#x4E2A;&#x7C7B;&#x7684;&#x5185;&#x90E8;&#x53C8;&#x5B9A;&#x4E49;&#x4E86;&#x5176;&#x4ED6;&#x7C7B;&#x3002;</p>
<p>&#x5982;&#x679C;&#x5728;&#x7C7B;Outer&#x7684;&#x5185;&#x90E8;&#x518D;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;Inner&#xFF0C;&#x6B64;&#x65F6;&#x7C7B;Inner&#x5C31;&#x79F0;&#x4E3A;&#x5185;&#x90E8;&#x7C7B;&#xFF0C;&#x800C;&#x7C7B;Outer&#x5219;&#x79F0;&#x4E3A;&#x5916;&#x90E8;&#x7C7B;&#x3002;</p>
<p>&#x5185;&#x90E8;&#x7C7B;&#x53EF;&#x58F0;&#x660E;&#x4E3A;public&#x6216;private&#x3002;</p>
<p>&#x5F53;&#x5185;&#x90E8;&#x7C7B;&#x58F0;&#x660E;&#x4E3A;public&#x6216;private&#x65F6;&#xFF0C;&#x5BF9;&#x5176;&#x8BBF;&#x95EE;&#x7684;&#x9650;&#x5236;&#x4E0E;&#x6210;&#x5458;&#x53D8;&#x91CF;&#x548C;&#x6210;&#x5458;&#x65B9;&#x6CD5;&#x5B8C;&#x5168;&#x76F8;&#x540C;&#x3002;</p>
<h4 id="93&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x540D;&#x79F0;&#x4E0D;&#x9700;&#x8981;&#x548C;java&#x6587;&#x4EF6;&#x76F8;&#x540C;&#x3002;">9.3&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x540D;&#x79F0;&#x4E0D;&#x9700;&#x8981;&#x548C;.java&#x6587;&#x4EF6;&#x76F8;&#x540C;&#x3002;</h4>
<p>9.3.1 &#x5185;&#x90E8;&#x7C7B;&#x7684;&#x57FA;&#x672C;&#x5B9A;&#x4E49;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x5B9A;&#x4E49;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>&#x6807;&#x8BC6;&#x7B26; class &#x5916;&#x90E8;&#x7C7B;&#x7684;&#x540D;&#x79F0;{&#x3000; // &#x5916;&#x90E8;&#x7C7B;&#x7684;&#x6210;&#x5458;&#x3000; &#x6807;&#x8BC6;&#x7B26; class &#x5185;&#x90E8;&#x7C7B;&#x7684;&#x540D;&#x79F0; &#x3000; {&#x3000;&#x3000;  // &#x5185;&#x90E8;&#x7C7B;&#x7684;&#x6210;&#x5458; &#x3000; }}&#x5185;&#x90E8;&#x7C7B;&#x4E3B;&#x8981;&#x6709;&#x5982;&#x4E0B;&#x4F5C;&#x7528;&#x3002;</p>
<p>&#xFF08;1&#xFF09;&#x5185;&#x90E8;&#x7C7B;&#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x597D;&#x7684;&#x5C01;&#x88C5;&#xFF0C;&#x53EF;&#x4EE5;&#x628A;&#x5185;&#x90E8;&#x7C7B;&#x9690;&#x85CF;&#x5728;&#x5916;&#x90E8;&#x7C7B;&#x4E4B;&#x5185;&#xFF0C;&#x4E0D;&#x5141;&#x8BB8;&#x540C;&#x4E00;&#x4E2A;&#x5305;&#x4E2D;&#x7684;&#x5176;&#x4ED6;&#x7C7B;&#x8BBF;&#x95EE;&#x8BE5;&#x7C7B;&#x3002;</p>
<p>&#xFF08;2&#xFF09;&#x5185;&#x90E8;&#x7C7B;&#x6210;&#x5458;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8BBF;&#x95EE;&#x5916;&#x90E8;&#x7C7B;&#x7684;&#x79C1;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x56E0;&#x4E3A;&#x5185;&#x90E8;&#x7C7B;&#x88AB;&#x5F53;&#x6210;&#x5176;&#x5916;&#x90E8;&#x7C7B;&#x6210;&#x5458;&#xFF0C;&#x540C;&#x4E00;&#x4E2A;&#x7C7B;&#x7684;&#x6210;&#x5458;&#x4E4B;&#x95F4;&#x53EF;&#x4EE5;&#x76F8;&#x4E92;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x4F46;&#x5916;&#x90E8;&#x7C7B;&#x4E0D;&#x80FD;&#x8BBF;&#x95EE;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x5B9E;&#x73B0;&#x7EC6;&#x8282;&#xFF0C;&#x4F8B;&#x5982;&#xFF0C;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x6210;&#x5458;&#x53D8;&#x91CF;&#x3002;</p>
<p>&#xFF08;3&#xFF09;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x9002;&#x5408;&#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x90A3;&#x4E9B;&#x4EC5;&#x9700;&#x8981;&#x4E00;&#x6B21;&#x7684;&#x7C7B;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-10 &#x5185;&#x90E8;&#x7C7B;&#x7684;&#x4F7F;&#x7528;&#xFF08;ObjectInnerDemo.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">class</span> <span class="token class-name">Outer</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">int</span> score <span class="token operator">=</span> 
<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">void</span> <span class="token function">inst</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Inner</span> in <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Inner</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  in<span class="token punctuation">.</span><span class="token function">display</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>&#x3000;&#x3000; 
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Inner</span> 
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token comment">// &#x5728;&#x5185;&#x90E8;&#x7C7B;&#x4E2D;&#x58F0;&#x660E;&#x4E00;&#x4E2A;name&#x5C5E;&#x6027;</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">String</span> name <span class="token operator">=</span> <span class="token string">&quot;&#x5F20;&#x4E09;&quot;</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">void</span> <span class="token function">display</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">{</span>&#x3000;&#x3000;&#x3000;&#x3000;
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6210;&#x7EE9;: score = &quot;</span> <span class="token operator">+</span> score<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//&#x8F93;&#x51FA;&#x5916;&#x90E8;&#x7C7B;&#x4E2D;&#x7684;&#x5C5E;&#x6027;</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token punctuation">}</span> 
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ObjectInnerDemo</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Outer</span> outer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Outer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  outer<span class="token punctuation">.</span><span class="token function">inst</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;04~08&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;inst()&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x4E8E;&#x5B9E;&#x4F8B;&#x5316;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x5BF9;&#x8C61;in&#x3002;</p>
<p>&#x7B2C;09~17&#x884C;&#xFF0C;&#x5728;Outer&#x7C7B;&#x7684;&#x5185;&#x90E8;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;Inner&#x7C7B;&#xFF0C;&#x6B64;&#x7C7B;&#x4E2D;&#x6709;&#x4E00;&#x4E2A;display()&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x4E8E;&#x6253;&#x5370;&#x5916;&#x90E8;&#x7C7B;&#x4E2D;&#x7684;score&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x4ECE;&#x7A0B;&#x5E8F;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x5185;&#x90E8;&#x7C7B;Inner&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x5916;&#x90E8;&#x7C7B;Outer&#x4E2D;&#x7684;score&#x5C5E;&#x6027;&#xFF0C;&#x73B0;&#x5728;&#x5982;&#x679C;&#x628A;&#x5185;&#x90E8;&#x7C7B;&#x62FF;&#x5230;&#x5916;&#x9762;&#x6765;&#x5355;&#x72EC;&#x58F0;&#x660E;&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x4F7F;&#x7528;&#x5916;&#x90E8;&#x7C7B;Outer&#x4E2D;&#x7684;score&#x5C5E;&#x6027;&#x65F6;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x5148;&#x4EA7;&#x751F;Outer&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x518D;&#x7531;&#x5BF9;&#x8C61;&#x901A;&#x8FC7;&#x70B9;&#x64CD;&#x4F5C;&#xFF08;&#x201C;.&#x201D;&#xFF09;&#xFF0C;&#x8C03;&#x7528;Outer&#x7C7B;&#x4E2D;&#x7684;&#x516C;&#x6709;&#x63A5;&#x53E3;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x516C;&#x6709;&#x65B9;&#x6CD5;&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x7531;&#x8FD9;&#x4E9B;&#x516C;&#x6709;&#x63A5;&#x53E3;&#x201C;&#x95F4;&#x63A5;&#x201D;&#x5730;&#x8BBF;&#x95EE;score&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x7531;&#x6B64;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x7531;&#x4E8E;&#x4F7F;&#x7528;&#x4E86;&#x5185;&#x90E8;&#x7C7B;&#x64CD;&#x4F5C;&#xFF0C;&#x7A0B;&#x5E8F;&#x5728;&#x8BBF;&#x95EE;score&#x5C5E;&#x6027;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x51CF;&#x5C11;&#x4E86;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x4ECE;&#x800C;&#x7701;&#x53BB;&#x4E86;&#x4E00;&#x90E8;&#x5206;&#x7684;&#x5185;&#x5B58;&#x5F00;&#x9500;&#x3002;</p>
<p>&#x9700;&#x8981;&#x8BFB;&#x8005;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x5185;&#x90E8;&#x7C7B;&#x662F;&#x4E00;&#x4E2A;&#x7F16;&#x8BD1;&#x65F6;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x4E00;&#x65E6;&#x7F16;&#x8BD1;&#x6210;&#x529F;&#xFF0C;&#x4E8B;&#x5B9E;&#x4E0A;&#xFF0C;&#x5C31;&#x4F1A;&#x751F;&#x6210;&#x5B8C;&#x5168;&#x4E0D;&#x540C;&#x7684;&#x4E24;&#x4E2A;&#x7C7B;&#xFF08;&#x7C7B;&#x4E2A;&#x6570;&#x603B;&#x548C;&#x53D6;&#x51B3;&#x4E8E;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x4E2A;&#x6570;&#x52A0;&#x4E0A;&#x5916;&#x90E8;&#x7C7B;&#x4E2A;&#x6570;&#xFF09;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;Outer&#x7684;&#x5916;&#x90E8;&#x7C7B;&#x548C;&#x540D;&#x4E3A;Inner&#x7684;&#x5185;&#x90E8;&#x7C7B;&#xFF0C;&#x7F16;&#x8BD1;&#x5B8C;&#x6210;&#x540E;&#x51FA;&#x73B0;Outer.class&#x548C;Outer$Inner.class&#x4E24;&#x4E2A;&#x7C7B;&#xFF0C;&#x4EE5;&#x53CA;&#x5305;&#x542B;&#x4E3B;&#x65B9;&#x6CD5;&#x7684;&#x6D4B;&#x8BD5;&#x7C7B;ObjectInnerDemo&#xFF0C;&#x5982;&#x4E0A;&#x56FE;&#x6240;&#x793A;&#xFF0C;&#x5176;&#x4E2D;Outer$Inner.class&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7F16;&#x8BD1;&#x597D;&#x7684;&#x5185;&#x90E8;&#x7C7B;&#xFF0C;&#x800C;&#x201C;$&#x201D;&#x5C31;&#x8868;&#x793A;&#x96B6;&#x5C5E;&#x5173;&#x7CFB;&#x3002;</p>
<p>&#x5728;&#x8FD0;&#x884C;&#x65F6;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x53EA;&#x80FD;&#x7528;java &#x6765;&#x89E3;&#x6790;&#x542B;&#x6709;&#x4E3B;&#x65B9;&#x6CD5;&#x7684;&#x7C7B;ObjectInnerDemo&#x3002;</p>
<p>9.3.2 &#x5728;&#x65B9;&#x6CD5;&#x4E2D;&#x5B9A;&#x4E49;&#x5185;&#x90E8;&#x7C7B;&#x5185;&#x90E8;&#x7C7B;&#x4E0D;&#x4EC5;&#x53EF;&#x4EE5;&#x5728;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x5728;&#x65B9;&#x6CD5;&#x4F53;&#x6216;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#xFF08;&#x5373;&#x7531;&#x201C;&#xFF5B;&#xFF5D;&#x201D;&#x62EC;&#x8D77;&#x6765;&#x7684;&#x533A;&#x57DF;&#xFF09;&#x3002;</p>
<p>&#x8FD9;&#x6837;&#x7684;&#x5185;&#x90E8;&#x7C7B;&#x4F5C;&#x7528;&#x8303;&#x56F4;&#x4EC5;&#x5C40;&#x9650;&#x4E8E;&#x65B9;&#x6CD5;&#x4F53;&#x6216;&#x7279;&#x5B9A;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#xFF0C;&#x56E0;&#x6B64;&#x4E5F;&#x79F0;&#x4E3A;&#x5C40;&#x90E8;&#x5185;&#x90E8;&#x7C7B;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x4E3E;&#x4F8B;&#x8BF4;&#x660E;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-11 &#x5728;&#x65B9;&#x6CD5;&#x4E2D;&#x5B9A;&#x4E49;&#x5185;&#x90E8;&#x7C7B;&#xFF08;ObjectInnerClass.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">class</span> <span class="token class-name">InnerClassTest</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">int</span> score <span class="token operator">=</span> 
<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">void</span> <span class="token function">inst</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">class</span> <span class="token class-name">Inner</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token keyword">void</span> <span class="token function">display</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6210;&#x7EE9;: score = &quot;</span> <span class="token operator">+</span> score<span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token punctuation">}</span>
&#x3000;&#x3000;&#x3000;  <span class="token punctuation">}</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">Inner</span> in <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Inner</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  in<span class="token punctuation">.</span><span class="token function">display</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ObjectInnerClass</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">InnerClassTest</span> outer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">InnerClassTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  outer<span class="token punctuation">.</span><span class="token function">inst</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x5728;InnerClassTest&#x7C7B;&#x4E2D;&#x7684;&#x7B2C;04~15&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;inst( )&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x6B64;&#x65B9;&#x6CD5;&#x4E2D;&#x53C8;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x53EB;Inner&#x7684;&#x5185;&#x90E8;&#x7C7B;&#xFF0C;&#x540C;&#x65F6;&#x4EA7;&#x751F;&#x4E86;Inner&#x7684;&#x5185;&#x90E8;&#x7C7B;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#xFF08;&#x7B2C;13&#x884C;&#xFF09;&#xFF0C;&#x8C03;&#x7528;&#x5176;&#x5185;&#x90E8;&#x7684;&#x65B9;&#x6CD5;display( )&#xFF08;&#x7B2C;14&#x884C;&#xFF09;&#x3002;</p>
<p>&#x7B2C;21&#x884C;&#x4EA7;&#x751F;&#x4E86;&#x4E00;&#x4E2A;InnerClassTest&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;outer&#xFF0C;&#x5E76;&#x5728;&#x7B2C;22&#x884C;&#x8C03;&#x7528;Outer&#x7C7B;&#x4E2D;&#x7684;inst( )&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x4E0B;&#x8FD0;&#x884C;Java&#x7A0B;&#x5E8F;&#xFF0C;&#x53EF;&#x4EE5;&#x663E;&#x793A;&#x66F4;&#x591A;&#x7EC6;&#x8282;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x50CF;&#x4E0A;&#x4E00;&#x4E2A;&#x7C7B;&#x4E00;&#x6837;&#xFF0C;&#x7F16;&#x8BD1;&#x5B8C;&#x6210;&#x540E;&#x51FA;&#x73B0;&#x591A;&#x4E2A;&#x7C7B;&#xFF0C;&#x800C;&#x4E14;&#x53EA;&#x80FD;&#x7528;java&#x6765;&#x89E3;&#x6790;&#x542B;&#x6709;&#x4E3B;&#x65B9;&#x6CD5;&#x7684;&#x7C7B;ObjectInnerClass&#x3002;</p>
<p>&#x50CF;&#x5176;&#x4ED6;&#x7C7B;&#x4E00;&#x6837;&#xFF0C;&#x5C40;&#x90E8;&#x5185;&#x90E8;&#x7C7B;&#x4E5F;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x7F16;&#x8BD1;&#xFF0C;&#x6240;&#x4E0D;&#x540C;&#x7684;&#x662F;&#xFF0C;&#x4F5C;&#x7528;&#x57DF;&#x4E0D;&#x540C;&#x800C;&#x5DF2;&#xFF0C;&#x5C40;&#x90E8;&#x5185;&#x90E8;&#x7C7B;&#x53EA;&#x5728;&#x8BE5;&#x65B9;&#x6CD5;&#x6216;&#x6761;&#x4EF6;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x624D;&#x80FD;&#x4F7F;&#x7528;&#xFF0C;&#x51FA;&#x4E86;&#x8FD9;&#x4E9B;&#x4F5C;&#x7528;&#x57DF;&#x540E;&#xFF0C;&#x4FBF;&#x65E0;&#x6CD5;&#x5F15;&#x7528;&#x3002;</p>
<p>&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x628A;&#x5C40;&#x90E8;&#x5185;&#x90E8;&#x7C7B;&#x60F3;&#x8C61;&#x6210;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x666E;&#x901A;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5728;&#x67D0;&#x4E2A;&#x65B9;&#x6CD5;&#x4F53;&#x5185;&#x6216;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x51FA;&#x4E86;&#x5B83;&#x6240;&#x5B9A;&#x4E49;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x8303;&#x56F4;&#xFF0C;&#x5B83;&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x5C31;&#x5230;&#x5934;&#x4E86;&#xFF0C;&#x5176;&#x4ED6;&#x5730;&#x65B9;&#x81EA;&#x7136;&#x4E5F;&#x5C31;&#x65E0;&#x6CD5;&#x5F15;&#x7528;&#x5B83;&#x3002;</p>
<p><a id="4"></a></p>
<h3 id="94-&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;">9.4 &#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;</h3>
<p>&#x6709;&#x65F6;&#x5019;&#xFF0C;&#x6211;&#x4EEC;&#x61D2;&#x5F97;&#x53BB;&#x7ED9;&#x5185;&#x90E8;&#x7C7B;&#x547D;&#x540D;&#xFF0C;&#x8FD9;&#x65F6;&#x5C31;&#x503E;&#x5411;&#x4E8E;&#x4F7F;&#x7528;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x3002;</p>
<p>&#x56E0;&#x4E3A;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x6CA1;&#x6709;&#x540D;&#x5B57;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x7684;&#x521B;&#x5EFA;&#x65B9;&#x5F0F;&#x4E5F;&#x6BD4;&#x8F83;&#x7279;&#x522B;&#x3002;</p>
<p>&#x521B;&#x5EFA;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>new &#x7236;&#x7C7B;&#x6784;&#x9020;&#x5668;&#xFF08;&#x53C2;&#x6570;&#x5217;&#x8868;&#xFF09;|&#x5B9E;&#x73B0;&#x63A5;&#x53E3;(){ //&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x7C7B;&#x4F53;&#x90E8;&#x5206; }&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x4F7F;&#x7528;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#xFF0C;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x8981;&#x7EE7;&#x627F;&#x4E00;&#x4E2A;&#x7236;&#x7C7B;&#x6216;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF1A;&#x2460;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x662F;&#x6CA1;&#x6709;class&#x5173;&#x952E;&#x5B57;&#x505A;&#x4FEE;&#x9970;&#x7684;&#xFF1B;&#x2461; &#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x662F;&#x76F4;&#x63A5;&#x4F7F;&#x7528;new&#x6765;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#x3002;</p>
<p>&#x5728;new&#x4E4B;&#x524D;&#xFF0C;&#x8FD9;&#x4E2A;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x662F;&#x8981;&#x5148;&#x5B9A;&#x4E49;&#x7684;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-12 &#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x4F7F;&#x7528;&#x5B9E;&#x4F8B;&#xFF08;AnonymousInnerClass.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Bird</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">private</span> <span class="token class-name">String</span> name<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> name<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setName</span><span class="token punctuation">(</span><span class="token class-name">String</span> name<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">int</span> <span class="token function">fly</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AnonymousInnerClass</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">birdBehaviour</span><span class="token punctuation">(</span><span class="token class-name">Bird</span> bird<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>bird<span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> &#x201C;&#x6700;&#x9AD8;&#x80FD;&#x98DE; <span class="token string">&quot; + bird.fly() + &quot;</span>&#x7C73;&quot;<span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">AnonymousInnerClass</span> <span class="token class-name">AnonyObjObj</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AnonymousInnerClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">AnonyObjObj</span><span class="token punctuation">.</span><span class="token function">birdBehaviour</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Bird</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">fly</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> <span class="token number">1000</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> <span class="token string">&quot;&#x5C0F;&#x9E1F;&quot;</span><span class="token punctuation">;</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x4EE3;&#x7801;&#x7B2C;01~13&#x884C;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;Bird&#xFF0C;&#x91CC;&#x9762;&#x6709;&#x4E2A;&#x4EC5;&#x6709;&#x65B9;&#x6CD5;&#x58F0;&#x660E;&#x800C;&#x65E0;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x2014;&#x2014;fly( )&#x3002;</p>
<p>&#x6839;&#x636E;&#x524D;&#x9762;&#x5B66;&#x4E60;&#x5230;&#x7684;&#x77E5;&#x8BC6;&#xFF0C;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;&#x5982;&#x679C;&#x62BD;&#x8C61;&#x7C7B;Bird&#x5185;&#x90E8;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x6CA1;&#x6709;&#x5177;&#x4F53;&#x5316;&#xFF0C;&#x6C38;&#x8FDC;&#x90FD;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x7528;new&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x3002;</p>
<p>&#x7B2C;17&#x884C;&#xFF0C;&#x5728;birdBehaviour&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x5217;&#x8868;&#x4E2D;&#xFF0C;bird&#x4EC5;&#x4EC5;&#x4F5C;&#x4E3A;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#x5F62;&#x53C2;&#x2014;&#x2014;&#x4E5F;&#x5C31;&#x662F;&#x5F62;&#x5F0F;&#x4E0A;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x6362;&#x53E5;&#x8BDD;&#x8BF4;&#xFF0C;&#x5B83;&#x5929;&#x751F;&#x5C31;&#x662F;&#x6765;&#x63A5;&#x7EB3;&#x5B9E;&#x53C2;&#xFF08;&#x5B9E;&#x9645;&#x4E0A;&#x7684;&#x53C2;&#x6570;&#xFF09;&#x6765;&#x8D4B;&#x503C;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x53C2;&#x6570;&#x5217;&#x8868;&#x4E2D;&#x5E76;&#x4E0D;&#x6D89;&#x53CA;&#x751F;&#x6210;&#x65B0;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5728;&#x7B2C;23&#x884C;&#xFF0C;&#x751F;&#x4EA7;&#x4E00;&#x4E2A;AnonymousInnerClass&#x7C7B;&#x7684;&#x5BF9;&#x8C61;AnonyObjObj&#x3002;</p>
<p>&#x63A5;&#x7740;&#xFF0C;&#x91CD;&#x70B9;&#x6765;&#x4E86;&#xFF0C;&#x5728;&#x7B2C;24&#x884C;&#xFF0C;&#x5BF9;&#x8C61;AnonyObjObj&#x4F7F;&#x7528;&#x81EA;&#x5DF1;&#x7C7B;&#x7684;&#x516C;&#x6709;&#x65B9;&#x6CD5;birdBehaviour( )&#xFF0C;&#x6B64;&#x523B;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x8981;&#x505A;&#x5B9E;&#x4E86;&#xFF0C;&#x5B83;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5B9E;&#x5B9E;&#x5728;&#x5728;&#x7684;Bird&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x800C;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;Bird&#x672C;&#x8EAB;&#x8FD8;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x60F3;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#xFF0C;&#x5FC5;&#x987B;&#x5148;&#x628A;&#x8FD9;&#x4E2A;&#x7C7B;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x53D8;&#x5F97;&#x4E0D;&#x62BD;&#x8C61;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x8BBE;&#x8BA1;&#x5B9E;&#x73B0;&#x90E8;&#x5206;&#xFF09;&#x3002;</p>
<p>&#x5047;&#x8BBE;&#x8FD9;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x975E;&#x62BD;&#x8C61;&#x5316;&#x4EC5;&#x4EC5;&#x5C31;&#x7528;&#x4E00;&#x6B21;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x7C7B;&#x5B9A;&#x4E49;&#x51FA;&#x6765;&#x7684;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x53EB;&#x4EC0;&#x4E48;&#x540D;&#x5B57;&#x4E5F;&#x65E0;&#x6240;&#x8C13;&#xFF0C;&#x7D22;&#x6027;&#x5C31;&#x4E0D;&#x7ED9;&#x5B83;&#x53D6;&#x540D;&#x5B57;&#xFF0C;&#x7528;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x7C7B;&#x597D;&#x4E86;&#x3002;</p>
<p>&#x4E8E;&#x662F;&#xFF0C;&#x5728;&#x7B2C;25~35&#x884C;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x5C31;&#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x4E86;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x4E3B;&#x8981;&#x76EE;&#x7684;&#x8FD8;&#x662F;&#x8BA9;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;fly( )&#x4E0D;&#x518D;&#x62BD;&#x8C61;&#x4E86;&#x3002;</p>
<p>&#x7136;&#x540E;&#xFF0C;&#x7B2C;24&#x884C;&#x7528;new &#x64CD;&#x4F5C;&#xFF0C;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x65E0;&#x540D;&#x5C0F;&#x9E1F;bird&#xFF0C;&#x5F53;&#x4F5C;&#x5B9E;&#x53C2;&#xFF0C;&#x4F20;&#x9012;&#x7ED9;birdBehaviour( )&#x3002;</p>
<p>&#x7531;&#x6B64;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x7B2C;24~35&#x884C;&#x4EE3;&#x7801;&#x7684;&#x76EE;&#x7684;&#x5C31;&#x662F;&#x8981;&#x751F;&#x4EA7;&#x51FA;&#x6765;&#x4E00;&#x4E2A;&#x201C;&#x4E00;&#x6B21;&#x6027;&#x201D;&#x7684;&#x3001;&#x7528;&#x5B8C;&#x5C31;&#x6254;&#x7684;Bird&#x7C7B;&#x5B9E;&#x4F8B;&#x800C;&#x5DF2;&#x3002;</p>
<p>&#x4F46;&#x56E0;&#x4E3A;&#x8FD9;&#x79CD;&#x201C;&#x5077;&#x61D2;&#x201D;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x8BA9;&#x4EE3;&#x7801;&#x7684;&#x53EF;&#x8BFB;&#x6027;&#x53D8;&#x5F97;&#x8F83;&#x5DEE;&#xFF0C;&#x6240;&#x4EE5;&#x5E76;&#x4E0D;&#x63A8;&#x8350;&#x3002;</p>
<p>&#x8BF7;&#x8BFB;&#x8005;&#x601D;&#x8003;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x8303;&#x4F8B;&#x4E2D;&#xFF0C;&#x5982;&#x4F55;&#x6539;&#x6210;&#x53EF;&#x8BFB;&#x6027;&#x8F83;&#x597D;&#x7684;&#x975E;&#x533F;&#x540D;&#x7C7B;&#x5B9E;&#x73B0;&#x540C;&#x6837;&#x7684;&#x529F;&#x80FD;&#xFF1F;&#x63D0;&#x793A;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x7F3A;&#x9677;&#xFF0C;&#x5C31;&#x662F;&#x5B83;&#x4EC5;&#x80FD;&#x88AB;&#x4F7F;&#x7528;&#x4E00;&#x6B21;&#xFF0C;&#x521B;&#x5EFA;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x65F6;&#xFF0C;&#x5B83;&#x4F1A;&#x7ACB;&#x5373;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x8BE5;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x8BE5;&#x7C7B;&#x7684;&#x5B9A;&#x4E49;&#x4F1A;&#x7ACB;&#x5373;&#x6D88;&#x5931;&#xFF0C;&#x6240;&#x4EE5;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x4E0D;&#x80FD;&#x591F;&#x88AB;&#x91CD;&#x590D;&#x4F7F;&#x7528;&#x3002;
<a id="5"></a></p>
<h3 id="95-&#x533F;&#x540D;&#x5BF9;&#x8C61;">9.5 &#x533F;&#x540D;&#x5BF9;&#x8C61;</h3>
<p>&#x533F;&#x540D;&#x5BF9;&#x8C61;&#xFF0C;&#x987E;&#x540D;&#x601D;&#x4E49;&#xFF0C;&#x5C31;&#x662F;&#x6CA1;&#x6709;&#x660E;&#x786E;&#x7684;&#x58F0;&#x660E;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x8BFB;&#x8005;&#x4E5F;&#x53EF;&#x4EE5;&#x7B80;&#x5355;&#x5730;&#x7406;&#x89E3;&#x4E3A;&#x53EA;&#x4F7F;&#x7528;&#x4E00;&#x6B21;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5373;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x4E00;&#x4E2A;&#x5177;&#x4F53;&#x7684;&#x5BF9;&#x8C61;&#x540D;&#x79F0;&#x5F15;&#x7528;&#x5B83;&#x3002;</p>
<p>&#x8BF7;&#x770B;&#x4E0B;&#x9762;&#x7684;&#x8303;&#x4F8B;&#x3002;</p>
<p>&#x8303;&#x4F8B;9-13 &#x533F;&#x540D;&#x5BF9;&#x8C61;&#x7684;&#x4F7F;&#x7528;&#xFF08;AnonymousObject.java&#xFF09;</p>
<pre class="language-"><code class="lang-java">&#x3000;<span class="token keyword">class</span> <span class="token class-name">Person</span>
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000; <span class="token keyword">private</span> <span class="token class-name">String</span> name <span class="token operator">=</span> <span class="token string">&quot;&#x5F20;&#x4E09;&quot;</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">private</span> <span class="token keyword">int</span> age <span class="token operator">=</span> 
<span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">talk</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token keyword">return</span> <span class="token string">&quot;&#x6211;&#x662F;&#xFF1A;&quot;</span> <span class="token operator">+</span> name <span class="token operator">+</span> <span class="token string">&quot;&#xFF0C;&#x4ECA;&#x5E74;&#xFF1A;&quot;</span> <span class="token operator">+</span> age <span class="token operator">+</span> <span class="token string">&quot;&#x5C81;&quot;</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
&#x3000;<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AnonymousObject</span> 
&#x3000;<span class="token punctuation">{</span>
&#x3000;&#x3000;<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span>
&#x3000;&#x3000; <span class="token punctuation">{</span>
&#x3000;&#x3000;&#x3000;  <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Person</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">talk</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
&#x3000;&#x3000; <span class="token punctuation">}</span>
&#x3000;<span class="token punctuation">}</span>
</code></pre>
<p>&#x4FDD;&#x5B58;&#x5E76;&#x8FD0;&#x884C;&#x7A0B;&#x5E8F;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x8BE6;&#x89E3;&#x7B2C;01~09&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;Person&#x7C7B;&#xFF0C;&#x91CC;&#x9762;&#x6709;name&#x548C;age&#x4E24;&#x4E2A;&#x79C1;&#x6709;&#x5C5E;&#x6027;&#xFF0C;&#x5E76;&#x5206;&#x522B;&#x8D4B;&#x4E86;&#x521D;&#x503C;&#x3002;</p>
<p>&#x7B2C;14&#x884C;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;Person&#x533F;&#x540D;&#x5BF9;&#x8C61;&#xFF0C;&#x901A;&#x8FC7;&#x201C;new Person( )&#x201D;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x5BF9;&#x8C61;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x901A;&#x8FC7;&#x201C;&#x5BF9;&#x8C61;.&#x65B9;&#x6CD5;&#x540D;&#x201D;&#x7684;Java&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#xFF0C;&#x8C03;&#x7528;Person&#x7C7B;&#x4E2D;&#x7684;talk( )&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x3010;&#x8303;&#x4F8B;&#x5206;&#x6790;&#x3011;&#x4ECE;&#x7A0B;&#x5E8F;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x7528;&#x201C;new Person( )&#x201D;&#x58F0;&#x660E;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5B83;&#x5E76;&#x6CA1;&#x6709;&#x8D4B;&#x7ED9;&#x4EFB;&#x4F55;&#x4E00;&#x4E2A;Person&#x7C7B;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x6240;&#x4EE5;&#x6B64;&#x5BF9;&#x8C61;&#x53EA;&#x4F7F;&#x7528;&#x4E86;&#x4E00;&#x6B21;&#xFF0C;&#x7528;&#x5B8C;&#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x4F1A;&#x88AB;Java&#x7684;&#x5783;&#x573E;&#x6536;&#x96C6;&#x5668;&#x56DE;&#x6536;&#x3002;</p>
<p>&#x73B0;&#x5728;&#x603B;&#x7ED3;&#x4E00;&#x4E0B;&#x533F;&#x540D;&#x5BF9;&#x8C61;&#x7684;&#x7279;&#x70B9;&#x3002;</p>
<p>&#xFF08;1&#xFF09;&#x533F;&#x540D;&#x5BF9;&#x8C61;&#x4E0D;&#x4F1A;&#x88AB;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x6240;&#x5F15;&#x7528;&#x3002;</p>
<p>&#xFF08;2&#xFF09;&#x533F;&#x540D;&#x5BF9;&#x8C61;&#x662F;&#x201C;&#x4E00;&#x6B21;&#x6027;&#xFF08;disposable&#xFF09;&#x201D;&#x7684;&#x5BF9;&#x8C61;&#x4EA7;&#x54C1;&#xFF0C;&#x4F7F;&#x7528;&#x4E00;&#x6B21;&#x5C31;&#x53D8;&#x6210;&#x5783;&#x573E;&#x4E86;&#xFF0C;&#x88AB;&#x5783;&#x573E;&#x56DE;&#x6536;&#x5668;&#x6536;&#x56DE;&#x4E86;&#x3002;</p>
<p>&#x6709;&#x610F;&#x601D;&#x7684;&#x662F;&#xFF0C;&#x82F1;&#x6587;&#x5355;&#x8BCD;&#x4E2D;&#x7684;&#x201C;disposable&#x201D;&#xFF0C;&#x6709;&#x201C;&#x53EF;&#x4EFB;&#x610F;&#x5904;&#x7406;&#x7684;&#x201D;&#x548C;&#x201C;&#x7528;&#x5B8C;&#x5373;&#x53EF;&#x4E22;&#x5F03;&#x7684;&#x201D;&#x8FD9;&#x4E24;&#x5C42;&#x542B;&#x4E49;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x5F62;&#x5BB9;&#x201C;&#x533F;&#x540D;&#x5BF9;&#x8C61;&#x201D;&#x3002;</p>
<p><a id="6"></a></p>
<h3 id="96-&#x9AD8;&#x624B;&#x70B9;&#x62E8;">9.6 &#x9AD8;&#x624B;&#x70B9;&#x62E8;</h3>
<ol>
<li>&#x7EE7;&#x627F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x548C;&#x7EE7;&#x627F;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7C7B;&#x7684;&#x4E3B;&#x8981;&#x533A;&#x522B;&#xFF08;1&#xFF09;&#x5728;&#x666E;&#x901A;&#x7C7B;&#x4E4B;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x65B9;&#x6CD5;&#x90FD;&#x662F;&#x6709;&#x65B9;&#x6CD5;&#x4F53;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x8BF4;&#x6709;&#x4E00;&#x4E9B;&#x65B9;&#x6CD5;&#x5E0C;&#x671B;&#x7531;&#x5B50;&#x7C7B;&#x5B9E;&#x73B0;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5B50;&#x7C7B;&#x5373;&#x4F7F;&#x4E0D;&#x5B9E;&#x73B0;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#x3002;</li>
</ol>
<p>&#x800C;&#x5982;&#x679C;&#x91CD;&#x5199;&#x6539;&#x5199;&#x4E86;&#x7236;&#x7C7B;&#x7684;&#x540C;&#x540D;&#x65B9;&#x6CD5;&#xFF0C;&#x5C31;&#x6784;&#x6210;&#x4E86;&#x201C;&#x8986;&#x5199;&#x201D;&#x3002;</p>
<p>&#xFF08;2&#xFF09;&#x5982;&#x679C;&#x4F7F;&#x7528;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x8BDD;&#xFF0C;&#x90A3;&#x4E48;&#x62BD;&#x8C61;&#x7C7B;&#x4E4B;&#x4E2D;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x8BED;&#x6CD5;&#x89C4;&#x5219;&#x4E0A;&#x5C31;&#x5FC5;&#x987B;&#x8981;&#x6C42;&#x5B50;&#x7C7B;&#x7ED9;&#x4E88;&#x5B9E;&#x73B0;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x53EF;&#x4EE5;&#x5F3A;&#x5236;&#x5B50;&#x7C7B;&#x505A;&#x4E00;&#x4E9B;&#x56FA;&#x5B9A;&#x64CD;&#x4F5C;&#x3002;</p>
<ol>
<li>&#x63A5;&#x53E3;&#x4E0D;&#x80FD;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;&#x7684;&#x53D8;&#x91CF;&#xFF08;&#x5F15;&#x7528;&#xFF09;&#xFF0C;&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;faceA &#x3002;</li>
</ol>
<p>interface  faceA  // &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;A
{&#x3000;&#x3000; 
    void doSomething( );
}</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x5B9A;&#x4E49;&#x662F;&#x5408;&#x6CD5;&#x7684;&#x3002;</p>
<p>faceA myface;&#x4F46;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x80FD;&#x7528;&#x63A5;&#x53E3;&#x6784;&#x9020;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5982;&#x4E0B;&#x4EE3;&#x7801;&#x662F;&#x9519;&#x8BEF;&#x7684;&#x3002;</p>
<pre class="language-"><code class="lang-java">faceA myface <span class="token operator">=</span> <span class="token function">faceA</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// &#x9519;&#x8BEF;&#x539F;&#x56E0;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x63A5;&#x53E3;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x7C7B;&#xFF0C;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#x57FA;&#x672C;&#x4E0A;&#x90FD;&#x662F;&#x62BD;&#x8C61;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x80FD;&#x7528;&#x5B83;&#x6784;&#x9020;&#xFF08;&#x901A;&#x8FC7;new&#x64CD;&#x4F5C;&#xFF09;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</span>
</code></pre>
<p>&#x4F46;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x53D8;&#x91CF;&#xFF08;&#x5373;&#x5F15;&#x7528;&#xFF09;&#x5374;&#x53EF;&#x4EE5;&#x6307;&#x5411;&#x5B83;&#x7684;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x201C;&#x5B9E;&#x73B0;&#x201D;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x7684;&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#xFF09;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">class</span>  myClass <span class="token keyword">implements</span> faceA  <span class="token comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;A</span>
<span class="token punctuation">{</span>&#x3000;&#x3000; 
    <span class="token annotation punctuation">@Override</span>&#x3000; <span class="token keyword">void</span> <span class="token function">doSomething</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>&#x3000; 
    <span class="token punctuation">{</span>&#x3000;&#x3000;  
        <span class="token class-name">Doing</span> something<span class="token punctuation">;</span>&#x3000;
    <span class="token punctuation">}</span>&#x3000; 
    <span class="token keyword">void</span> <span class="token function">doNewSomething</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>&#x3000; 
    <span class="token punctuation">{</span>&#x3000;&#x3000;  
        <span class="token class-name">Doing</span> <span class="token keyword">new</span> thing<span class="token punctuation">;</span>&#x3000; 
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class="language-"><code class="lang-java">faceA  myface <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token function">myClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//&#x6B63;&#x786E;&#xFF0C;&#x4F46;&#x53EA;&#x80FD;&#x8BBF;&#x95EE;myClass&#x4ECE;&#x63A5;&#x53E3;faceA&#x201C;&#x5B9E;&#x73B0;&#x201D;&#x7684;&#x65B9;&#x6CD5;</span>
</code></pre>
<ol>
<li>&#x63A5;&#x53E3;&#x3001;&#x62BD;&#x8C61;&#x7C7B;&#x3001;&#x7C7B;&#x3001;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x7CFB;&#xFF08;1&#xFF09;&#x57FA;&#x672C;&#x7C7B;&#xFF1A;&#x4E5F;&#x5C31;&#x662F;&#x4E00;&#x822C;&#x7684;&#x7C7B;&#xFF08;&#x4E00;&#x822C;&#x6240;&#x8BF4;&#x7684;&#x7C7B;&#x5C31;&#x662F;&#x57FA;&#x672C;&#x7C7B;&#xFF09;&#xFF0C;&#x662F;&#x5BF9;&#x8C61;&#x7684;&#x6A21;&#x677F;&#xFF0C;&#x662F;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x96C6;&#x5408;&#x3002;</li>
</ol>
<p>&#x53EF;&#x4EE5;&#x7EE7;&#x627F;&#x5176;&#x4ED6;&#x7684;&#x57FA;&#x672C;&#x7C7B;&#xFF08;&#x7EE7;&#x627F;&#x4E00;&#x4E2A;&#xFF09;&#x3001;&#x62BD;&#x8C61;&#x7C7B;&#xFF08;&#x7EE7;&#x627F;&#x4E00;&#x4E2A;&#xFF09;&#x3001;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF08;&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#xFF09;&#x3002;</p>
<p>&#xFF08;2&#xFF09;&#x62BD;&#x8C61;&#x7C7B;&#xFF1A;&#x6709;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x7C7B;(&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x8BE5;&#x65B9;&#x6CD5;&#x5FC5;&#x987B;&#x7531;&#x7EE7;&#x627F;&#x6765;&#x5B9E;&#x73B0;&#xFF0C;&#x672C;&#x8EAB;&#x53EA;&#x5B9A;&#x4E49;&#xFF0C;&#x4E0D;&#x5B9E;&#x73B0;)&#x3002;</p>
<p>&#x62BD;&#x8C61;&#x7C7B;&#x53EF;&#x4EE5;&#x6709;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x662F;&#x57FA;&#x672C;&#x7C7B;&#x548C;&#x63A5;&#x53E3;&#x7C7B;&#x7684;&#x8FC7;&#x6E21;&#x3002;</p>
<p>&#xFF08;3&#xFF09;&#x63A5;&#x53E3;&#xFF1A;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#x9664;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;&#xFF08;&#x5E26;&#x65B9;&#x6CD5;&#x4F53;&#xFF09;&#x5916;&#x90FD;&#x662F;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x672C;&#x8EAB;&#x53EA;&#x5B9A;&#x4E49;&#xFF0C;&#x4E0D;&#x5B9E;&#x73B0;&#xFF0C;&#x7528;&#x6765;&#x5236;&#x5B9A;&#x6807;&#x51C6;&#x3002;</p>
<p>&#x56DB;&#x8005;&#x95F4;&#x7684;&#x5173;&#x7CFB;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p>&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x6240;&#x8C13;&#x7684;&#x63A5;&#x53E3;&#x5C31;&#x662F;&#x6307;&#x5728;&#x7C7B;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x7684;&#x8FDB;&#x4E00;&#x6B65;&#x62BD;&#x8C61;&#xFF08;&#x62BD;&#x79BB;&#x6570;&#x636E;&#xFF0C;&#x4FDD;&#x7559;&#x884C;&#x4E3A;&#xFF09;&#x3002;</p>
<p>&#x800C;&#x5F88;&#x591A;&#x65F6;&#x5019;&#x5728;&#x5F00;&#x53D1;&#x4E4B;&#x4E2D;&#xFF0C;&#x4E5F;&#x4F1A;&#x907F;&#x514D;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x51FA;&#x73B0;&#xFF0C;&#x56E0;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#x6BD5;&#x7ADF;&#x5B58;&#x5728;&#x5355;&#x7EE7;&#x627F;&#x7684;&#x5C40;&#x9650;&#x3002;</p>
<p>&#x7C7B;&#x4E0E;&#x7C7B;&#x4E4B;&#x95F4;&#x7684;&#x5171;&#x6027;&#x5C31;&#x6210;&#x4E86;&#x63A5;&#x53E3;&#x7684;&#x5B9A;&#x4E49;&#x6807;&#x51C6;&#x3002;</p>
<p>&#x7C7B;&#x3001;&#x62BD;&#x8C61;&#x7C7B;&#x3001;&#x63A5;&#x53E3;&#x4E4B;&#x95F4;&#x7684;&#x89D2;&#x8272;&#x626E;&#x6F14;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x5982;&#x4E0B;&#x7684;&#x4F8B;&#x5B50;&#x6765;&#x505A;&#x7C7B;&#x6BD4;&#x3002;</p>
<p>&#x6BD4;&#x5982;&#x8BF4;&#xFF0C;&#x5728;&#x4E00;&#x4E2A;&#x516C;&#x53F8;&#x91CC;&#xFF0C;&#x6709;&#x8001;&#x677F;&#x3001;&#x8001;&#x677F;&#x8058;&#x7528;&#x7684;&#x7ECF;&#x7406;&#x548C;&#x5458;&#x5DE5;3&#x79CD;&#x89D2;&#x8272;&#x3002;</p>
<p>&#x666E;&#x901A;&#x7C7B;&#x5C31;&#x597D;&#x6BD4;&#x662F;&#x5458;&#x5DE5;&#xFF0C;&#x62BD;&#x8C61;&#x7C7B;&#x5C31;&#x597D;&#x6BD4;&#x662F;&#x7ECF;&#x7406;&#xFF0C;&#x63A5;&#x53E3;&#x5C31;&#x597D;&#x6BD4;&#x662F;&#x8001;&#x677F;&#x3002;</p>
<p>&#x5728;&#x63A5;&#x53E3;&#x91CC;&#xFF0C;&#x201C;&#x8001;&#x677F;&#x201D;&#x5C31;&#x662F;&#x52A8;&#x52A8;&#x5634;&#x76AE;&#x5B50;&#xFF0C;&#x5149;&#x63D0;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x4ED6;&#x81EA;&#x5DF1;&#x4E0D;&#x53BB;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x6BD4;&#x5982;&#xFF0C;&#x8001;&#x677F;&#x8BF4;&#x6211;&#x8981;&#x90A3;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x7ED9;&#x6211;&#x5B9A;&#x4E2A;&#x673A;&#x7968;&#xFF0C;&#x6211;&#x8981;&#x90A3;&#x4E2A;&#x7B56;&#x5212;&#x65B9;&#x6848;&#x7B49;&#xFF0C;&#x90FD;&#x662F;&#x624B;&#x4E0B;&#x7684;&#x4EBA;&#x53BB;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x5728;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#xFF0C;&#x5B83;&#x7ED9;&#x51FA;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x6709;&#x7684;&#x662F;&#x4ED6;&#x81EA;&#x5DF1;&#x505A;&#xFF0C;&#x6709;&#x7684;&#x662F;&#x5176;&#x4ED6;&#x4EBA;&#x505A;&#xFF08;&#x5373;&#x7EE7;&#x627F;&#x4E8E;&#x5B83;&#x8FD9;&#x4E2A;&#x7C7B;&#x7684;&#x5B50;&#x7C7B;&#xFF09;&#x3002;</p>
<p>&#x6BD4;&#x5982;&#x7ECF;&#x7406;&#x8BF4;&#x6211;&#x8981;&#x90A3;&#x4E2A;&#x6587;&#x6863;&#xFF0C;&#x5458;&#x5DE5;&#x5C31;&#x8981;&#x53D1;&#x7ED9;&#x4ED6;&#xFF0C;&#x4F46;&#x662F;&#x4ED6;&#x81EA;&#x5DF1;&#x4E5F;&#x8981;&#x505A;&#x70B9;&#x4E8B;&#xFF0C;&#x6BD4;&#x5982;&#x62FF;&#x65B9;&#x6848;&#x7ED9;&#x8001;&#x677F;&#x770B;&#x3002;</p>
<p>&#x4E00;&#x8A00;&#x853D;&#x4E4B;&#xFF0C;&#x7ECF;&#x7406;&#xFF08;&#x62BD;&#x8C61;&#x7C7B;&#xFF09;&#x9700;&#x8981;&#x53C8;&#x8BF4;&#x53C8;&#x505A;&#x3002;</p>
<p>&#x76F8;&#x6BD4;&#x800C;&#x8A00;&#xFF0C;&#x666E;&#x901A;&#x7C7B;&#x201C;&#x811A;&#x8E0F;&#x5B9E;&#x5730;&#x201D;&#xFF0C;&#x81EA;&#x5DF1;&#x7ED9;&#x51FA;&#x7684;&#x65B9;&#x6CD5;&#x8981;&#x975E;&#x5E38;&#x5177;&#x4F53;&#xFF0C;&#x4EC0;&#x4E48;&#x90FD;&#x8981;&#x5B9E;&#x73B0;&#xFF0C;&#x4EB2;&#x529B;&#x4EB2;&#x4E3A;&#x3002;</p>
<ol>
<li>&#x63A5;&#x53E3;&#x548C;&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x5E94;&#x7528;&#x62BD;&#x8C61;&#x7C7B;&#xFF08;abstract&#xFF09;&#x5728;Java&#x8BED;&#x8A00;&#x4E2D;&#x4F53;&#x73B0;&#x4E86;&#x4E00;&#x79CD;&#x7EE7;&#x627F;&#x5173;&#x7CFB;&#xFF0C;&#x8981;&#x60F3;&#x4F7F;&#x7EE7;&#x627F;&#x5173;&#x7CFB;&#x5408;&#x7406;&#xFF0C;&#x7236;&#x7C7B;&#x548C;&#x6D3E;&#x751F;&#x7C7B;&#x4E4B;&#x95F4;&#x5FC5;&#x987B;&#x5B58;&#x5728;&#x201C;IS A&#x201D;&#x5173;&#x7CFB;&#xFF0C;&#x5373;&#x7236;&#x7C7B;&#x548C;&#x6D3E;&#x751F;&#x7C7B;&#x5728;&#x6982;&#x5FF5;&#x672C;&#x8D28;&#x4E0A;&#x5E94;&#x8BE5;&#x662F;&#x76F8;&#x540C;&#x7684;&#x3002;</li>
</ol>
<p>&#x5BF9;&#x4E8E;interface &#x6765;&#x8BF4;&#x5219;&#x4E0D;&#x7136;&#xFF0C;&#x5E76;&#x4E0D;&#x8981;&#x6C42;interface&#x7684;&#x5B9E;&#x73B0;&#x8005;&#x548C;interface&#x5B9A;&#x4E49;&#x5728;&#x6982;&#x5FF5;&#x672C;&#x8D28;&#x4E0A;&#x662F;&#x4E00;&#x81F4;&#x7684;&#xFF0C;&#x4EC5;&#x4EC5;&#x662F;&#x5B9E;&#x73B0;&#x4E86;interface&#x5B9A;&#x4E49;&#x7684;&#x5951;&#x7EA6;&#x800C;&#x5DF2;&#x3002;</p>
<p>&#x8003;&#x8651;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x5047;&#x8BBE;&#x5EFA;&#x7ACB;&#x4E00;&#x4E2A;&#x5173;&#x4E8E;Door&#x7684;&#x62BD;&#x8C61;&#x6982;&#x5FF5;&#xFF0C;&#x4E00;&#x822C;&#x8BA4;&#x4E3A;Door&#x53EF;&#x6267;&#x884C;&#x4E24;&#x4E2A;&#x52A8;&#x4F5C;&#xFF1A;open&#x548C;close&#xFF0C;&#x82E5;&#x901A;&#x8FC7;abstract class&#x6216;interface&#x6765;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x8868;&#x793A;&#x8BE5;&#x62BD;&#x8C61;&#x6982;&#x5FF5;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x5B9A;&#x4E49;&#x65B9;&#x5F0F;&#x5206;&#x522B;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>&#x4F7F;&#x7528;abstract &#x7C7B;&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;Door&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Door</span> 
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  &#x3000; 
    <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4F7F;&#x7528;interface&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;Door&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">interface</span> <span class="token class-name">Door</span> 
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5176;&#x4ED6;&#x5177;&#x4F53;&#x5B50;&#x7C7B;&#xFF0C;&#x6BD4;&#x5982;&#x8BF4;&#x5B50;&#x7C7B;&#x2014;&#x2014;&#x6728;&#x95E8;&#x7C7B;&#xFF08;WoodDoor&#xFF09;&#x6216;&#x94C1;&#x95E8;&#x7C7B;&#xFF08;IronDoor&#xFF09;&#x7B49;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;extends&#xFF08;&#x6269;&#x5C55;&#xFF09;&#x7EE7;&#x627F;&#x62BD;&#x8C61;&#x7C7B;Door&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;open()&#x548C;close()&#x3002;</p>
<p>&#x7C7B;&#x4F3C;&#x5730;&#xFF0C;&#x6728;&#x95E8;&#x7C7B;&#x6216;&#x94C1;&#x95E8;&#x7C7B;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5173;&#x952E;&#x5B57;implements&#xFF0C;&#x540C;&#x6837;&#x7EE7;&#x627F;&#x4F7F;&#x7528;&#x63A5;&#x53E3;Door&#x4E2D;&#x7684;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x8FD9;&#x6837;&#x770B;&#x8D77;&#x6765;&#xFF0C;&#x4F7F;&#x7528;abstract class&#x548C;interface&#x597D;&#x50CF;&#x6CA1;&#x6709;&#x592A;&#x5927;&#x7684;&#x533A;&#x522B;&#x3002;</p>
<p>&#x4E8B;&#x5B9E;&#x4E0A;&#xFF0C;&#x5E76;&#x975E;&#x5982;&#x6B64;&#x3002;</p>
<p>&#x6BD4;&#x5982;&#x8BF4;&#xFF0C;&#x5982;&#x679C;&#x7528;&#x6237;&#x7684;&#x9700;&#x6C42;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF0C;&#x73B0;&#x5728;&#x8981;&#x6C42;&#x6240;&#x6709;&#x7684;Door&#x90FD;&#x8981;&#x5177;&#x5907;&#x62A5;&#x8B66;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x90A3;&#x8BE5;&#x5982;&#x4F55;&#x8BBE;&#x8BA1;&#x8FD9;&#x4E2A;&#x7C7B;&#x7ED3;&#x679C;&#x5462;&#xFF1F;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x4E00;&#x7B80;&#x5355;&#x5730;&#x5728;&#x62BD;&#x8C61;&#x7C7B;Door&#x4E2D;&#x65B0;&#x589E;&#x52A0;&#x4E00;&#x4E2A;alarm&#x7684;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Door</span>
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  &#x3000; 
    <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  &#x3000; 
    <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">alarm</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//&#x65B0;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x90A3;&#x4E48;&#xFF0C;&#x5177;&#x6709;&#x62A5;&#x8B66;&#x529F;&#x80FD;&#x7684;&#x5B50;&#x7C7B;AlarmDoor&#x7EE7;&#x627F;&#x4E0A;&#x8FF0;&#x53D8;&#x66F4;&#x7684;&#x7236;&#x7C7B;&#x5373;&#x53EF;&#xFF0C;&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">class</span> <span class="token class-name">AlarmDoor</span> <span class="token keyword">extends</span> <span class="token class-name">Door</span> 
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  <span class="token comment">//&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#x800C;&#x6765;&#x7684;&#x65B9;&#x6CD5;open()&#x3000; </span>
    <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  <span class="token comment">//&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#x800C;&#x6765;&#x7684;&#x65B9;&#x6CD5;close ()&#x3000; </span>
    <span class="token keyword">void</span> <span class="token function">alarm</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  <span class="token comment">//&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#x800C;&#x6765;&#x7684;&#x65B9;&#x6CD5;alarm ()</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x4FEE;&#x6539;&#x65B9;&#x5F0F;&#x662F;&#x5229;&#x7528;interface&#x5B9E;&#x73B0;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">interface</span> <span class="token class-name">Door</span> 
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token function">alarm</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//&#x65B0;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x62A5;&#x8B66;&#x63A5;&#x53E3;alarm</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x90A3;&#x4E48;&#xFF0C;&#x5177;&#x6709;&#x62A5;&#x8B66;&#x529F;&#x80FD;&#x7684;&#x5B50;&#x7C7B;AlarmDoor&#x901A;&#x8FC7;implements&#x7EE7;&#x627F;&#x63A5;&#x53E3;&#x6DFB;&#x52A0;&#x65B0;&#x65B9;&#x6CD5;&#xFF0C;&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">class</span> <span class="token class-name">AlarmDoor</span> <span class="token keyword">implements</span> <span class="token class-name">Door</span> 
&#xFF5B;  &#x3000; 
     <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  &#x3000; 
     <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  &#x3000; 
     <span class="token keyword">void</span> <span class="token function">alarm</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  
&#xFF5D;
</code></pre>
<p>&#x7136;&#x800C;&#xFF0C;&#x76F4;&#x63A5;&#x5728;&#x62BD;&#x8C61;&#x7C7B;&#x6216;&#x63A5;&#x53E3;&#x4E2D;&#x65B0;&#x589E;&#x52A0;alarm&#x65B9;&#x6CD5;&#xFF0C;&#x5176;&#x5B9E;&#x662F;&#x8FDD;&#x53CD;&#x4E86;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x8BBE;&#x8BA1;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x6838;&#x5FC3;&#x539F;&#x5219;&#x2014;&#x2014;&#x63A5;&#x53E3;&#x9694;&#x79BB;&#x539F;&#x5219;&#xFF08;Interface Segregation Principle&#xFF0C;ISP&#xFF09;&#x3002;</p>
<p>&#x524D;&#x9762;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x5373;&#x628A;Door&#x6982;&#x5FF5;&#x672C;&#x8EAB;&#x56FA;&#x6709;&#x7684;&#x884C;&#x4E3A;&#x65B9;&#x6CD5;&#xFF08;&#x5982;close&#x548C;open&#xFF09;&#x548C;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x6982;&#x5FF5;&#x201C;&#x62A5;&#x8B66;&#x5668;&#x201D;&#x7684;&#x884C;&#x4E3A;&#x65B9;&#x6CD5;&#x6DF7;&#x5728;&#x4E86;&#x4E00;&#x8D77;&#x3002;</p>
<p>&#x8FD9;&#x6837;&#x5C31;&#x4F1A;&#x5F15;&#x8D77;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x90A3;&#x4E9B;&#x4EC5;&#x4EC5;&#x4F9D;&#x8D56;&#x4E8E;Door&#x8FD9;&#x4E2A;&#x6982;&#x5FF5;&#x7684;&#x6A21;&#x5757;&#xFF0C;&#x4F1A;&#x56E0;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#xFF08;&#x7236;&#x7C7B;&#xFF09;&#x201C;&#x6DFB;&#x52A0;&#x62A5;&#x8B66;&#x5668;&#x201D;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x6539;&#x53D8;&#x800C;&#x88AB;&#x8FEB;&#x6539;&#x53D8;&#xFF0C;&#x5E76;&#x4E0D;&#x662F;&#x6240;&#x6709;&#x7684;&#x5B50;&#x7C7B;&#x90FD;&#x9700;&#x8981;&#x62A5;&#x8B66;&#x529F;&#x80FD;&#x7684;&#x3002;</p>
<p>&#x5728;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x4E2D;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x65B0;&#x65B9;&#x6CD5;&#xFF0C;&#x4E5F;&#x4F1A;&#x5BFC;&#x81F4;&#x6240;&#x6709;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x7684;&#x5B50;&#x7C7B;&#x88AB;&#x8FEB;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x5B83;&#x53EF;&#x80FD;&#x4E0D;&#x9700;&#x8981;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x6B64;&#x5916;&#xFF0C;&#x8FD9;&#x79CD;&#x4E0D;&#x65AD;&#x5730;&#x5728;&#x63A5;&#x53E3;&#x4E2D;&#x6DFB;&#x52A0;&#x65B0;&#x65B9;&#x6CD5;&#x7684;&#x7B56;&#x7565;&#xFF0C;&#x4E5F;&#x4F1A;&#x4F7F;&#x539F;&#x6765;&#x7684;Door&#x63A5;&#x53E3;&#x53D8;&#x5F97;&#x8D8A;&#x6765;&#x8D8A;&#x201C;&#x80D6;&#x201D;&#xFF0C;&#x8FD9;&#x5C31;&#x662F;&#x6240;&#x8C13;&#x7684;&#x201C;&#x63A5;&#x53E3;&#x6C61;&#x67D3;&#x201D;&#x3002;</p>
<p>&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x4E8C;&#x4E8B;&#x5B9E;&#x4E0A;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x6709;&#x7B2C;&#x4E8C;&#x79CD;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x663E;&#x7136;&#xFF0C;open&#x3001;close&#x548C;alarm&#x5C5E;&#x4E8E;&#x4E24;&#x4E2A;&#x4E0D;&#x540C;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x524D;&#x4E24;&#x4E2A;&#xFF08;open&#x3001;close&#xFF09;&#x662F;&#x5FC5;&#x5907;&#x529F;&#x80FD;&#xFF0C;&#x800C;alarm&#x662F;&#x9644;&#x52A0;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x6839;&#x636E;ISP&#x539F;&#x5219;&#xFF0C;&#x5E94;&#x8BE5;&#x628A;&#x5B83;&#x4EEC;&#x5206;&#x522B;&#x5B9A;&#x4E49;&#x5728;&#x4EE3;&#x8868;&#x8FD9;&#x4E24;&#x7C7B;&#x6982;&#x5FF5;&#x7684;&#x4E24;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x4E2D;&#x3002;</p>
<p>&#x5B9A;&#x4E49;&#x7684;&#x53EF;&#x80FD;&#x65B9;&#x5F0F;&#x6709;3&#x79CD;&#x3002;</p>
<p>&#xFF08;1&#xFF09;&#x8FD9;&#x4E24;&#x4E2A;&#x6982;&#x5FF5;&#x90FD;&#x4F7F;&#x7528;abstract class&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;&#x3002;</p>
<p>&#x70B9;&#x8BC4;&#xFF1A;&#x56E0;&#x4E3A;Java&#x8BED;&#x8A00;&#x4E0D;&#x652F;&#x6301;&#x591A;&#x91CD;&#x7EE7;&#x627F;&#xFF0C;&#x6240;&#x4EE5;&#x4E24;&#x4E2A;&#x6982;&#x5FF5;&#x90FD;&#x4F7F;&#x7528;abstractclass&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;&#x662F;&#x4E0D;&#x53EF;&#x884C;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x5176;&#x5B50;&#x7C7B;&#x4E0D;&#x53EF;&#x80FD;&#x540C;&#x65F6;&#x7EE7;&#x627F;&#x201C;Door&#x201D;&#x548C;&#x201C;Alarm&#x201D;&#x4E24;&#x4E2A;&#x7C7B;&#xFF0C;&#x4ECE;&#x800C;&#x8FBE;&#x6210;AlarmDoor&#x529F;&#x80FD;&#x7684;&#x6C47;&#x96C6;&#x3002;</p>
<p>&#xFF08;2&#xFF09;&#x4E24;&#x4E2A;&#x6982;&#x5FF5;&#x90FD;&#x4F7F;&#x7528;interface&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;&#x3002;</p>
<p>&#x70B9;&#x8BC4;&#xFF1A;&#x5728;&#x6982;&#x5FF5;&#x672C;&#x8D28;&#x4E0A;&#xFF0C;&#x65E0;&#x6CD5;&#x660E;&#x786E;&#x4F53;&#x73B0;AlarmDoor&#xFF0C;&#x5230;&#x5E95;&#x662F;Door&#xFF0C;&#x8FD8;&#x662F;&#x62A5;&#x8B66;&#x5668;&#xFF0C;&#x65E0;&#x6CD5;&#x53CD;&#x6620;AlarmDoor&#x5728;&#x6982;&#x5FF5;&#x672C;&#x8D28;&#x4E0A;&#x548C;Door&#x662F;&#x4E00;&#x81F4;&#x7684;&#x3002;</p>
<p>&#xFF08;3&#xFF09;&#x4E00;&#x4E2A;&#x6982;&#x5FF5;&#x4F7F;&#x7528;abstract class&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;&#xFF0C;&#x53E6;&#x4E00;&#x4E2A;&#x6982;&#x5FF5;&#x4F7F;&#x7528;interface&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;&#x3002;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Door</span> 
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  &#x3000; 
    <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#xFF1B;  
<span class="token punctuation">}</span>  
<span class="token keyword">interface</span> <span class="token class-name">Alarm</span> 
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token function">alarm</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  
<span class="token punctuation">}</span>  
<span class="token keyword">class</span> <span class="token class-name">AlarmDoor</span> <span class="token keyword">extends</span> <span class="token class-name">Door</span> <span class="token keyword">implements</span> <span class="token class-name">Alarm</span> 
<span class="token punctuation">{</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token keyword">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  &#x3000; 
    <span class="token keyword">void</span> <span class="token function">alarm</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> &#x2026; <span class="token punctuation">}</span>  
<span class="token punctuation">}</span>
</code></pre>
<p>&#x70B9;&#x8BC4;&#xFF1A;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x201C;&#x4E2D;&#x5EB8;&#x201D;&#x7684;&#x65B9;&#x6848;&#xFF0C;&#x6BD4;&#x8F83;&#x7B26;&#x5408;&#x6211;&#x4EEC;&#x7684;&#x8981;&#x6C42;&#xFF0C;&#x5728;&#x6982;&#x5FF5;&#x4E0A;&#x7EE7;&#x627F;&#x4E86;&#x201C;Door&#x201D;&#x7684;&#x6240;&#x6709;&#x7279;&#x6027;&#xFF0C;&#x540C;&#x65F6;&#xFF0C;&#x53C8;&#x901A;&#x8FC7;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF0C;&#x5728;&#x529F;&#x80FD;&#x4E0A;&#x5B8C;&#x6210;&#x4E86;&#x201C;&#x6269;&#x5C55;&#x201D;&#x3002;</p>
<p>&#x62BD;&#x8C61;&#x7C7B;&#x5728;Java&#x8BED;&#x8A00;&#x4E2D;&#x8868;&#x793A;&#x4E00;&#x79CD;&#x7EE7;&#x627F;&#x5173;&#x7CFB;&#xFF0C;&#x800C;&#x7EE7;&#x627F;&#x5173;&#x7CFB;&#x5728;&#x672C;&#x8D28;&#x4E0A;&#x662F;&#x201C;is a&#x201D;&#x5173;&#x7CFB;&#xFF0C;&#x5BF9;&#x4E8E;Door&#x8FD9;&#x4E2A;&#x6982;&#x5FF5;&#xFF0C;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;abstract class&#x65B9;&#x5F0F;&#x6765;&#x5B9A;&#x4E49;&#x3002;</p>
<p>interface&#x8868;&#x793A;&#x7684;&#x662F;&#x201C;like a&#x201D;&#x5173;&#x7CFB;&#xFF0C;AlarmDoor&#x53C8;&#x5177;&#x6709;&#x62A5;&#x8B66;&#x529F;&#x80FD;&#xFF0C;&#x8BF4;&#x660E;&#x5B83;&#x53C8;&#x80FD;&#x591F;&#x5B8C;&#x6210;&#x62A5;&#x8B66;&#x6982;&#x5FF5;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x884C;&#x4E3A;&#x3002;
<a id="7"></a></p>
<h3 id="97-&#x5B9E;&#x6218;&#x7EC3;&#x4E60;">9.7 &#x5B9E;&#x6218;&#x7EC3;&#x4E60;</h3>
<p>1.&#x8BBE;&#x8BA1;&#x4E00;&#x4E2A;&#x9650;&#x5236;&#x5B50;&#x7C7B;&#x8BBF;&#x95EE;&#x7684;&#x62BD;&#x8C61;&#x7C7B;&#x5B9E;&#x4F8B;&#xFF0C;&#x8981;&#x6C42;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#x5982;&#x4E0B;&#x7ED3;&#x679C;&#x3002;</p>
<p>&#x6559;&#x5E08;&#x2014;&#x2014;&gt;&#x59D3;&#x540D;&#xFF1A;&#x5218;&#x4E09;&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;50&#xFF0C;&#x804C;&#x4E1A;&#xFF1A;&#x6559;&#x5E08;&#x5DE5;&#x4EBA;&#x2014;&#x2014;&gt;&#x59D3;&#x540D;&#xFF1A;&#x8D75;&#x56DB;&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;30&#xFF0C;&#x804C;&#x4E1A;&#xFF1A;&#x5DE5;&#x4EBA;2.&#x5229;&#x7528;&#x63A5;&#x53E3;&#x53CA;&#x62BD;&#x8C61;&#x7C7B;&#x8BBE;&#x8BA1;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#xFF08;1&#xFF09;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x5706;&#x5F62;CircleShape()&#xFF0C;&#x5176;&#x4E2D;&#x5B9A;&#x4E49;&#x5E38;&#x91CF;PI&#xFF0C;&#x9ED8;&#x8BA4;&#x65B9;&#x6CD5;area&#x8BA1;&#x7B97;&#x5706;&#x9762;&#x79EF;&#x3002;</p>
<p>&#xFF08;2&#xFF09;&#x5B9A;&#x4E49;&#x5706;&#x5F62;&#x7C7B;Circle&#x5B9E;&#x73B0;&#x63A5;&#x53E3;CircleShape&#xFF0C;&#x5305;&#x542B;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x548C;&#x6C42;&#x5706;&#x5468;&#x957F;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#xFF08;3&#xFF09;&#x5B9A;&#x4E49;&#x5706;&#x67F1;&#x7EE7;&#x627F;Circle&#x5B9E;&#x73B0;&#x63A5;&#x53E3;CircleShape&#xFF0C;&#x5305;&#x542B;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x3001;&#x5706;&#x67F1;&#x8868;&#x9762;&#x79EF;&#x3001;&#x4F53;&#x79EF;&#x3002;</p>
<p>&#xFF08;4&#xFF09;&#x4ECE;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x5165;&#x5706;&#x534A;&#x5F84;&#xFF0C;&#x8F93;&#x51FA;&#x5706;&#x9762;&#x79EF;&#x53CA;&#x5468;&#x957F;&#x3002;</p>
<p>&#xFF08;5&#xFF09;&#x4ECE;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x5165;&#x5706;&#x67F1;&#x5E95;&#x9762;&#x534A;&#x5F84;&#x53CA;&#x9AD8;&#xFF0C;&#x8F93;&#x51FA;&#x5706;&#x67F1;&#x5E95;&#x9762;&#x79EF;&#x3001;&#x5706;&#x67F1;&#x8868;&#x9762;&#x79EF;&#x53CA;&#x4F53;&#x79EF;&#x3002;</p>
<p>3.&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x201C;name&#x201D;&#x201C;age&#x201D;&#x548C;&#x201C;sex&#x201D;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x4F7F;&#x7528;&#x533F;&#x540D;&#x5BF9;&#x8C61;&#x8F93;&#x51FA;&#x5BF9;&#x8C61;&#x5B9E;&#x4F8B;&#x3002;</p>
<p>4.&#x5B8C;&#x6210;&#x4E00;&#x4E2A;&#x7EDF;&#x8BA1;Book&#x7C7B;&#x4EA7;&#x751F;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;&#x7684;&#x4E2A;&#x6570;&#x3002;</p>

</div>

                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="java12.html#11" class="navigation navigation-prev " aria-label="Previous page: 8.8 实战练习">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="java13.html#1" class="navigation navigation-next " aria-label="Next page: 9.1 抽象类">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"凝练才是美--抽象类 接口 内部类","level":"1.2.10","depth":2,"next":{"title":"9.1 抽象类","level":"1.2.10.1","depth":3,"anchor":"#1","path":"java13.md","ref":"java13.md#1","articles":[]},"previous":{"title":"8.8 实战练习","level":"1.2.9.8","depth":3,"anchor":"#11","path":"java12.md","ref":"java12.md#11","articles":[]},"dir":"ltr"},"config":{"plugins":["simple-mind-map","new-flowchart","mermaid-gb3@2.1.0","hide-element","-lunr","-search","search-plus@^0.0.11","back-to-top-button","openwrite","code","prism","-highlight","-livereload","expandable-chapters","timeline","todo","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"timeline":{},"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"new-flowchart":{},"todo":{},"code":{"copyButtons":true},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"openwrite":{"blogId":"18972-1576749538667-677","name":"谦谦君子","qrcode":"https://image.lichongbing.com/qrcode_for_gh_29bad7d68f3a_258.jpg","keyword":"更多"},"back-to-top-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"simple-mind-map":{"autoFit":true,"linkShape":"diagonal","preset":"colorful","style":{"height":"750px","wight":"1000px"},"type":"markdown"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"snowdreams1006","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Java笔记Blog","links":{"sidebar":{"blog":"https://blog.lichongbing.com/"}},"gitbook":"3.2.3","description":"gitbook-plugin-simple-mind-map examples"},"file":{"path":"java13.md","mtime":"2020-10-29T10:18:26.631Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-11-06T13:32:17.508Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    
    

    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-simple-mind-map/bundle.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-new-flowchart/raphael-min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-new-flowchart/flowchart-1.6.2.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-new-flowchart/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
var isMobile = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
if (!isMobile) {
    var btw = new BTWPlugin();
    btw.init({
        "id": "vip-container",
        "blogId": "18972-1576749538667-677",
        "name": "谦谦君子",
        "qrcode": "https://image.lichongbing.com/qrcode_for_gh_29bad7d68f3a_258.jpg",
        "keyword": "更多"
    });
}
</script>

    <script src="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>


    </body>
</html>

